-
Notifications
You must be signed in to change notification settings - Fork 944
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[api test] Added generic hooks for forever.Monitor
- Loading branch information
Showing
3 changed files
with
79 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* test-hook.js: Test hook fixture for raising an event on forever.Monitor `exit` | ||
* | ||
* (C) 2010 and Charlie Robbins | ||
* MIT LICENCE | ||
* | ||
*/ | ||
|
||
var events = require('events'), | ||
util = require('util'); | ||
|
||
var TestHook = exports.TestHook = function () { | ||
events.EventEmitter.call(this); | ||
}; | ||
|
||
util.inherits(TestHook, events.EventEmitter); | ||
|
||
TestHook.prototype.attach = function (monitor) { | ||
var self = this; | ||
monitor.on('exit', function () { | ||
self.emit.apply(['hook-exit'].concat(arguments)); | ||
}); | ||
}; |
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,41 @@ | ||
/* | ||
* hook-test.js: Tests for forever-based hooks | ||
* | ||
* (C) 2010 and Charlie Robbins | ||
* MIT LICENCE | ||
* | ||
*/ | ||
|
||
var sys = require('sys'), | ||
assert = require('assert'), | ||
path = require('path'), | ||
vows = require('vows'), | ||
forever = require('../lib/forever'), | ||
TestHook = require('./fixtures/test-hook').TestHook; | ||
|
||
vows.describe('forever/spin-restart').addBatch({ | ||
"When using forever": { | ||
"and spawning a script that spin restarts": { | ||
"with a simple hook": { | ||
topic: function () { | ||
var script = path.join(__dirname, '..', 'examples', 'always-throw.js'), | ||
child; | ||
|
||
child = new (forever.Monitor)(script, { | ||
silent: true, | ||
max: 1, | ||
hooks: [ | ||
new TestHook() | ||
] | ||
}); | ||
|
||
child.on('exit', this.callback.bind({}, null)); | ||
child.start(); | ||
}, | ||
"should raise the `hook-exit` event": function (err, child, spinning) { | ||
assert.isTrue(spinning); | ||
} | ||
} | ||
} | ||
} | ||
}).export(module); |