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: remove 1 second delay from test #4616

Closed
wants to merge 4 commits into from
Closed
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
42 changes: 21 additions & 21 deletions test/parallel/test-cluster-worker-wait-server-close.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,44 +5,44 @@ var assert = require('assert');
var cluster = require('cluster');
var net = require('net');

var serverClosed = false;

if (cluster.isWorker) {
net.createServer(function(socket) {
var server = net.createServer(function(socket) {
// Wait for any data, then close connection
socket.write('.');
socket.on('data', function discard() {
});
socket.on('data', function discard() {});
}).listen(common.PORT, common.localhostIPv4);
} else if (cluster.isMaster) {

var connectionDone;
var ok;
server.once('close', function() {
serverClosed = true;
});

// Although not typical, the worker process can exit before the disconnect
// event fires. Use this to keep the process open until the event has fired.
var keepOpen = setInterval(function() {}, 9999);

// Check worker events and properties
process.once('disconnect', function() {
// disconnect should occur after socket close
assert(serverClosed);
clearInterval(keepOpen);
});
} else if (cluster.isMaster) {
// start worker
var worker = cluster.fork();

var socket;
// Disconnect worker when it is ready
worker.once('listening', function() {
net.createConnection(common.PORT, common.localhostIPv4, function() {
var socket = this;
socket = this;
this.on('data', function() {
console.log('got data from client');
// socket definitely connected to worker if we got data
worker.disconnect();
setTimeout(function() {
socket.end();
connectionDone = true;
}, 1000);
socket.end();
});
});
});

// Check worker events and properties
worker.once('disconnect', function() {
assert.ok(connectionDone, 'disconnect should occur after socket close');
ok = true;
});

process.once('exit', function() {
assert.ok(ok);
});
}