11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciconst common = require('../common'); 31cb0ef41Sopenharmony_ci 41cb0ef41Sopenharmony_ci// This test ensures that the `'close'` event is emitted after the `'error'` 51cb0ef41Sopenharmony_ci// event when a request is made and the socket is closed before we started to 61cb0ef41Sopenharmony_ci// receive a response. 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_ciconst assert = require('assert'); 91cb0ef41Sopenharmony_ciconst http = require('http'); 101cb0ef41Sopenharmony_ci 111cb0ef41Sopenharmony_ciconst server = http.createServer(common.mustNotCall()); 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_ciserver.listen(0, common.mustCall(() => { 141cb0ef41Sopenharmony_ci const req = http.get({ port: server.address().port }, common.mustNotCall()); 151cb0ef41Sopenharmony_ci let errorEmitted = false; 161cb0ef41Sopenharmony_ci 171cb0ef41Sopenharmony_ci req.on('error', common.mustCall((err) => { 181cb0ef41Sopenharmony_ci errorEmitted = true; 191cb0ef41Sopenharmony_ci assert.strictEqual(err.constructor, Error); 201cb0ef41Sopenharmony_ci assert.strictEqual(err.message, 'socket hang up'); 211cb0ef41Sopenharmony_ci assert.strictEqual(err.code, 'ECONNRESET'); 221cb0ef41Sopenharmony_ci })); 231cb0ef41Sopenharmony_ci 241cb0ef41Sopenharmony_ci req.on('close', common.mustCall(() => { 251cb0ef41Sopenharmony_ci assert.strictEqual(req.destroyed, true); 261cb0ef41Sopenharmony_ci assert.strictEqual(errorEmitted, true); 271cb0ef41Sopenharmony_ci server.close(); 281cb0ef41Sopenharmony_ci })); 291cb0ef41Sopenharmony_ci 301cb0ef41Sopenharmony_ci req.destroy(); 311cb0ef41Sopenharmony_ci})); 32