Skip to content

Commit b60e690

Browse files
brendanashworthrvagg
authored andcommitted
test: improve test-net-server-pause-on-connect
Previously the test had a massive timeout (3s!), reduce this to a platform specific timeout of 50ms. This test runs two servers at the same time in an attempt to compare behaviour. I've added a check to make sure one event fires before the other event, as is expected, but that is a possible race condition. Improves test run time on my machine from 0m3.141s to 0m0.356s. PR-URL: #2429 Reviewed-By: Rich Trott <[email protected]>
1 parent 11d1b8f commit b60e690

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

test/parallel/test-net-server-pause-on-connect.js

+14-1
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,22 @@ var server1 = net.createServer({pauseOnConnect: true}, function(socket) {
1616
});
1717

1818
setTimeout(function() {
19+
// After 50(ish) ms, the other socket should have already read the data.
20+
assert.equal(read, true);
1921
assert.equal(socket.bytesRead, 0, 'no data should have been read yet');
22+
2023
socket.resume();
2124
stopped = false;
22-
}, 3000);
25+
}, common.platformTimeout(50));
2326
});
2427

28+
// read is a timing check, as server1's timer should fire after server2's
29+
// connection receives the data. Note that this could be race-y.
30+
var read = false;
2531
var server2 = net.createServer({pauseOnConnect: false}, function(socket) {
2632
socket.on('data', function(data) {
33+
read = true;
34+
2735
assert.equal(data.toString(), msg, 'invalid data received');
2836
socket.end();
2937
server2.close();
@@ -37,3 +45,8 @@ server1.listen(common.PORT, function() {
3745
server2.listen(common.PORT + 1, function() {
3846
net.createConnection({port: common.PORT + 1}).write(msg);
3947
});
48+
49+
process.on('exit', function() {
50+
assert.equal(stopped, false);
51+
assert.equal(read, true);
52+
});

0 commit comments

Comments
 (0)