11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ciconst common = require('../common');
41cb0ef41Sopenharmony_ciconst { createServer, get } = require('http');
51cb0ef41Sopenharmony_ciconst assert = require('assert');
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ciconst server = createServer(common.mustCall((req, res) => {
81cb0ef41Sopenharmony_ci  res.writeHead(200);
91cb0ef41Sopenharmony_ci  res.write('Part of res.');
101cb0ef41Sopenharmony_ci}));
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_cifunction onUncaught(error) {
131cb0ef41Sopenharmony_ci  assert.strictEqual(error.message, 'Destroy test');
141cb0ef41Sopenharmony_ci  server.close();
151cb0ef41Sopenharmony_ci}
161cb0ef41Sopenharmony_ci
171cb0ef41Sopenharmony_ciprocess.on('uncaughtException', common.mustCall(onUncaught));
181cb0ef41Sopenharmony_ci
191cb0ef41Sopenharmony_ciserver.listen(0, () => {
201cb0ef41Sopenharmony_ci  get({
211cb0ef41Sopenharmony_ci    port: server.address().port
221cb0ef41Sopenharmony_ci  }, common.mustCall((res) => {
231cb0ef41Sopenharmony_ci    const err = new Error('Destroy test');
241cb0ef41Sopenharmony_ci    assert.strictEqual(res.errored, null);
251cb0ef41Sopenharmony_ci    res.destroy(err);
261cb0ef41Sopenharmony_ci    assert.strictEqual(res.closed, false);
271cb0ef41Sopenharmony_ci    assert.strictEqual(res.errored, err);
281cb0ef41Sopenharmony_ci    res.on('close', () => {
291cb0ef41Sopenharmony_ci      assert.strictEqual(res.closed, true);
301cb0ef41Sopenharmony_ci    });
311cb0ef41Sopenharmony_ci  }));
321cb0ef41Sopenharmony_ci});
33