Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Also added gitignore and a test
- Loading branch information
Showing
4 changed files
with
73 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
*.un~ | ||
/node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
var test = require('fast-or-slow').slowTestCase(); | ||
var clusterIsolatable = require('./'); | ||
var cluster = require('cluster'); | ||
var http = require('http'); | ||
var assert = require('assert'); | ||
|
||
var options = { | ||
host: 'localhost', | ||
port: 3000, | ||
}; | ||
|
||
test('isolateWorker with custom timeout', function(done) { | ||
var server = http.createServer(function(req, res) { | ||
var timeout = parseInt(req.url.substr(1), 10); | ||
master.isolateWorker(timeout); | ||
|
||
res.writeHead(200, {'X-Pid': process.pid}); | ||
res.write('Hi'); | ||
}); | ||
|
||
var master = cluster(server) | ||
.set('workers', 1) | ||
.set('timeout', 1500) | ||
.use(clusterIsolatable()) | ||
.listen(options.port); | ||
|
||
|
||
var timeouts = [500, 1000]; | ||
var expectedTimeouts = []; | ||
|
||
master.on('worker connected', function() { | ||
var timeout = timeouts.shift(); | ||
if (!timeout) { | ||
return; | ||
} | ||
|
||
expectedTimeouts.push(timeout); | ||
options.path = '/' + timeout; | ||
|
||
http.get(options, function(res) { | ||
var pid = res.headers['x-pid']; | ||
process.kill(pid, 'SIGQUIT'); | ||
}); | ||
}); | ||
|
||
master.on('worker timeout', function(worker, timeout) { | ||
var expected = expectedTimeouts.shift(); | ||
assert.equal(timeout, expected); | ||
|
||
if (expectedTimeouts.length) { | ||
return; | ||
} | ||
|
||
assert.equal(master.children.length, 1); | ||
master.close(); | ||
}); | ||
|
||
process.on('exit', function() { | ||
assert.strictEqual(expectedTimeouts.length, 0); | ||
}); | ||
}); | ||
|
||
|