Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: some runtime speed improvements #2429

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions test/parallel/test-net-keepalive.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ var echoServer = net.createServer(function(connection) {
serverConnection = connection;
connection.setTimeout(0);
assert.notEqual(connection.setKeepAlive, undefined);
// send a keepalive packet after 1000 ms
connection.setKeepAlive(true, 1000);
// send a keepalive packet after 50 ms
connection.setKeepAlive(true, common.platformTimeout(50));
connection.on('end', function() {
connection.end();
});
Expand All @@ -27,5 +27,5 @@ echoServer.on('listening', function() {
serverConnection.end();
clientConnection.end();
echoServer.close();
}, 1200);
}, common.platformTimeout(100));
});
15 changes: 5 additions & 10 deletions test/parallel/test-net-pingpong.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,17 @@ function pingPongTest(port, host) {
// than one message.
assert.ok(0 <= socket.bufferSize && socket.bufferSize <= 4);

console.log('server got: ' + data);
assert.equal(true, socket.writable);
assert.equal(true, socket.readable);
assert.equal(true, count <= N);
if (/PING/.exec(data)) {
socket.write('PONG', function() {
sentPongs++;
console.error('sent PONG');
});
}
assert.equal(data, 'PING');

socket.write('PONG', function() {
sentPongs++;
});
});

socket.on('end', function() {
console.error(socket);
assert.equal(true, socket.allowHalfOpen);
assert.equal(true, socket.writable); // because allowHalfOpen
assert.equal(false, socket.readable);
Expand Down Expand Up @@ -73,8 +70,6 @@ function pingPongTest(port, host) {
});

client.on('data', function(data) {
console.log('client got: ' + data);

assert.equal('PONG', data);
count += 1;

Expand Down
15 changes: 14 additions & 1 deletion test/parallel/test-net-server-pause-on-connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,22 @@ var server1 = net.createServer({pauseOnConnect: true}, function(socket) {
});

setTimeout(function() {
// After 50(ish) ms, the other socket should have already read the data.
assert.equal(read, true);
assert.equal(socket.bytesRead, 0, 'no data should have been read yet');

socket.resume();
stopped = false;
}, 3000);
}, common.platformTimeout(50));
});

// read is a timing check, as server1's timer should fire after server2's
// connection receives the data. Note that this could be race-y.
var read = false;
var server2 = net.createServer({pauseOnConnect: false}, function(socket) {
socket.on('data', function(data) {
read = true;

assert.equal(data.toString(), msg, 'invalid data received');
socket.end();
server2.close();
Expand All @@ -37,3 +45,8 @@ server1.listen(common.PORT, function() {
server2.listen(common.PORT + 1, function() {
net.createConnection({port: common.PORT + 1}).write(msg);
});

process.on('exit', function() {
assert.equal(stopped, false);
assert.equal(read, true);
});