test: fix flaky test-net-write-after-close
Replace 250ms timer with event-based logic to make test robust. PR-URL: https://github.com/nodejs/node/pull/14361 Fixes: https://github.com/nodejs/node/issues/13597 Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
27343cc051
commit
43bd47c352
@ -21,24 +21,31 @@
|
|||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
const common = require('../common');
|
const common = require('../common');
|
||||||
|
|
||||||
const net = require('net');
|
const net = require('net');
|
||||||
|
|
||||||
|
let serverSocket;
|
||||||
|
|
||||||
const server = net.createServer(common.mustCall(function(socket) {
|
const server = net.createServer(common.mustCall(function(socket) {
|
||||||
|
serverSocket = socket;
|
||||||
|
|
||||||
socket.resume();
|
socket.resume();
|
||||||
|
|
||||||
socket.on('error', common.mustCall(function(error) {
|
socket.on('error', common.mustCall(function(error) {
|
||||||
console.error('got error, closing server', error);
|
console.error('received error as expected, closing server', error);
|
||||||
server.close();
|
server.close();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
setTimeout(common.mustCall(function() {
|
|
||||||
console.error('about to try to write');
|
|
||||||
socket.write('test', common.mustCall());
|
|
||||||
}), 250);
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
server.listen(0, function() {
|
server.listen(0, function() {
|
||||||
const client = net.connect(this.address().port, function() {
|
const client = net.connect(this.address().port, function() {
|
||||||
|
// cliend.end() will close both the readable and writable side
|
||||||
|
// of the duplex because allowHalfOpen defaults to false.
|
||||||
|
// Then 'end' will be emitted when it receives a FIN packet from
|
||||||
|
// the other side.
|
||||||
|
client.on('end', common.mustCall(() => {
|
||||||
|
serverSocket.write('test', common.mustCall());
|
||||||
|
}));
|
||||||
client.end();
|
client.end();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user