1'use strict'; 2const common = require('../common'); 3 4const assert = require('assert'); 5const net = require('net'); 6 7const { expectsError, mustCall } = common; 8 9// This test ensures those errors caused by calling `net.Socket.write()` 10// after sockets ending will be emitted in the next tick. 11const server = net.createServer(mustCall((socket) => { 12 socket.end(); 13})).listen(() => { 14 const client = net.connect(server.address().port, () => { 15 let hasError = false; 16 client.on('error', mustCall((err) => { 17 hasError = true; 18 server.close(); 19 })); 20 client.on('end', mustCall(() => { 21 const ret = client.write('hello', expectsError({ 22 code: 'EPIPE', 23 message: 'This socket has been ended by the other party', 24 name: 'Error' 25 })); 26 27 assert.strictEqual(ret, false); 28 assert(!hasError, 'The error should be emitted in the next tick.'); 29 })); 30 client.end(); 31 }); 32}); 33