test: fix test-net-settimeout flakiness
Wait for the data to be received by the socket before creating the clean-up timer. This way, a possible (though unlikely) `ECONNRESET` error can be avoided. PR-URL: https://github.com/nodejs/node/pull/6166 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
This commit is contained in:
parent
c7fef3d3b8
commit
bf22c71a7a
@ -8,22 +8,24 @@ const assert = require('assert');
|
||||
|
||||
const T = 100;
|
||||
|
||||
const server = net.createServer(function(c) {
|
||||
const server = net.createServer(common.mustCall((c) => {
|
||||
c.write('hello');
|
||||
});
|
||||
}));
|
||||
|
||||
server.listen(common.PORT);
|
||||
|
||||
const socket = net.createConnection(common.PORT, 'localhost');
|
||||
|
||||
const s = socket.setTimeout(T, function() {
|
||||
const s = socket.setTimeout(T, () => {
|
||||
common.fail('Socket timeout event is not expected to fire');
|
||||
});
|
||||
assert.ok(s instanceof net.Socket);
|
||||
|
||||
socket.on('data', common.mustCall(() => {
|
||||
setTimeout(function() {
|
||||
socket.destroy();
|
||||
server.close();
|
||||
}, T * 2);
|
||||
}));
|
||||
|
||||
socket.setTimeout(0);
|
||||
|
||||
setTimeout(function() {
|
||||
socket.destroy();
|
||||
server.close();
|
||||
}, T * 2);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user