Skip to content

Commit 2992012

Browse files
committed
test: refactor flaky net-error-twice
The test was not reliably creating the error event on Windows 2012. This makes the test more robust by delaying the start of the server write until nextTick, allowing the connection to close and cause the error more reliably on Windows 2012. Fixes: nodejs#4057
1 parent d1000b4 commit 2992012

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

test/parallel/test-net-error-twice.js

+10-14
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,29 @@
11
'use strict';
2-
var common = require('../common');
3-
var assert = require('assert');
4-
var net = require('net');
2+
const common = require('../common');
3+
const assert = require('assert');
4+
const net = require('net');
55

6-
var buf = new Buffer(10 * 1024 * 1024);
6+
const buf = new Buffer(10 * 1024 * 1024);
77

88
buf.fill(0x62);
99

1010
var errs = [];
1111

12-
var srv = net.createServer(function onConnection(conn) {
13-
conn.write(buf);
12+
const srv = net.createServer(function onConnection(conn) {
13+
process.nextTick(() => { conn.write(buf); });
1414
conn.on('error', function(err) {
1515
errs.push(err);
16-
if (errs.length > 1 && errs[0] === errs[1])
17-
assert(false, 'We should not be emitting the same error twice');
16+
if (errs.length > 1)
17+
assert(errs[0] !== errs[1], 'Should not get the same error twice');
1818
});
1919
conn.on('close', function() {
2020
srv.unref();
2121
});
2222
}).listen(common.PORT, function() {
23-
var client = net.connect({ port: common.PORT });
24-
25-
client.on('connect', function() {
26-
client.destroy();
27-
});
23+
const client = net.connect({ port: common.PORT });
24+
client.on('connect', client.destroy);
2825
});
2926

3027
process.on('exit', function() {
31-
console.log(errs);
3228
assert.equal(errs.length, 1);
3329
});

0 commit comments

Comments
 (0)