forked from nodules/luster
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Worker is not marked dead on requested stop
- Loading branch information
Slava Baginov
committed
Aug 12, 2019
1 parent
b8b7537
commit 67ebeda
Showing
7 changed files
with
99 additions
and
2 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
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,39 @@ | ||
const proc = require('luster'); | ||
|
||
proc | ||
.configure({ | ||
app: 'worker.js', | ||
workers: 1, | ||
control: { | ||
stopTimeout: 100, | ||
exitThreshold: 50, | ||
allowedSequentialDeaths: 0, | ||
} | ||
}, true, __dirname) | ||
.run(); | ||
|
||
if (proc.isMaster) { | ||
proc.once('running', () => { | ||
process.send('ready'); | ||
}); | ||
|
||
proc.on('worker exit', worker => { | ||
console.log(`Worker ${worker.wid} has exited, dead is ${worker.dead}`); | ||
}); | ||
|
||
process.on('message', message => { | ||
switch (message) { | ||
case 'worker quit': | ||
proc.emitToAll('quit'); | ||
break; | ||
case 'worker restart': | ||
proc.forEach(worker => worker.restart()); | ||
break; | ||
case 'worker stop': | ||
proc.forEach(worker => worker.stop()); | ||
break; | ||
default: | ||
throw new Error(`Got unknown command ${message}`); | ||
} | ||
}); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,5 @@ | ||
const worker = require('luster'); | ||
|
||
worker.on('master quit', () => { | ||
process.disconnect(); | ||
}); |
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,50 @@ | ||
/* globals describe,it,before,after,assert */ | ||
'use strict'; | ||
|
||
const LusterInstance = require('../helpers/luster_instance'); | ||
const delay = require('delay'); | ||
|
||
describe('dead workers', () => { | ||
let instance; | ||
|
||
beforeEach(async () => { | ||
instance = await LusterInstance | ||
.run('../fixtures/dead_workers/master.js'); | ||
}); | ||
|
||
it('worker quitting before exitThreshold should be marked as dead', async () => { | ||
await instance.sendWaitTimeout('worker quit', 50); | ||
|
||
const expectedEvents = 'Worker 1 has exited, dead is true\n'; | ||
assert.equal(instance.output(), expectedEvents); | ||
}); | ||
|
||
it('worker quitting after exitThreshold should not be marked as dead', async () => { | ||
await delay(50); | ||
await instance.sendWaitTimeout('worker quit', 50); | ||
|
||
const expectedEvents = 'Worker 1 has exited, dead is false\n'; | ||
assert.equal(instance.output(), expectedEvents); | ||
}); | ||
|
||
it('worker restarted manually should not be marked as dead', async () => { | ||
await instance.sendWaitTimeout('worker restart', 50); | ||
|
||
const expectedEvents = 'Worker 1 has exited, dead is false\n'; | ||
assert.equal(instance.output(), expectedEvents); | ||
}); | ||
|
||
it('worker stopped manually should not be marked as dead', async () => { | ||
await instance.sendWaitTimeout('worker stop', 50); | ||
|
||
const expectedEvents = 'Worker 1 has exited, dead is false\n'; | ||
assert.equal(instance.output(), expectedEvents); | ||
}); | ||
|
||
afterEach(() => { | ||
if (instance) { | ||
instance.kill(); | ||
instance = null; | ||
} | ||
}); | ||
}); |