11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciconst common = require('../common'); 31cb0ef41Sopenharmony_ci 41cb0ef41Sopenharmony_ciconst assert = require('assert'); 51cb0ef41Sopenharmony_ciconst net = require('net'); 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ciconst { expectsError, mustCall } = common; 81cb0ef41Sopenharmony_ci 91cb0ef41Sopenharmony_ci// This test ensures those errors caused by calling `net.Socket.write()` 101cb0ef41Sopenharmony_ci// after sockets ending will be emitted in the next tick. 111cb0ef41Sopenharmony_ciconst server = net.createServer(mustCall((socket) => { 121cb0ef41Sopenharmony_ci socket.end(); 131cb0ef41Sopenharmony_ci})).listen(() => { 141cb0ef41Sopenharmony_ci const client = net.connect(server.address().port, () => { 151cb0ef41Sopenharmony_ci let hasError = false; 161cb0ef41Sopenharmony_ci client.on('error', mustCall((err) => { 171cb0ef41Sopenharmony_ci hasError = true; 181cb0ef41Sopenharmony_ci server.close(); 191cb0ef41Sopenharmony_ci })); 201cb0ef41Sopenharmony_ci client.on('end', mustCall(() => { 211cb0ef41Sopenharmony_ci const ret = client.write('hello', expectsError({ 221cb0ef41Sopenharmony_ci code: 'EPIPE', 231cb0ef41Sopenharmony_ci message: 'This socket has been ended by the other party', 241cb0ef41Sopenharmony_ci name: 'Error' 251cb0ef41Sopenharmony_ci })); 261cb0ef41Sopenharmony_ci 271cb0ef41Sopenharmony_ci assert.strictEqual(ret, false); 281cb0ef41Sopenharmony_ci assert(!hasError, 'The error should be emitted in the next tick.'); 291cb0ef41Sopenharmony_ci })); 301cb0ef41Sopenharmony_ci client.end(); 311cb0ef41Sopenharmony_ci }); 321cb0ef41Sopenharmony_ci}); 33