-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathtimeout.test.js
70 lines (60 loc) · 2.06 KB
/
timeout.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/**
* Module dependencies
*/
var Machine = require('../');
describe('timeout', function (){
describe('machine that never triggers its exits', function (){
describe('with timeout configured for 0.25 seconds', function (){
var machineInstance;
before(function (){
machineInstance = Machine.build({
timeout: 250,
fn: function machineThatNeverTriggersItsExits(inputs, exits, env){
// beep
}
});
});
it('should call its error exit with a timeout error', function (done){
machineInstance().exec({
error: function (err) {
if (err.code === 'E_MACHINE_TIMEOUT') {
return done();
}
return done(new Error('Expecting Error instance w/ `code` === "E_MACHINE_TIMEOUT", but instead got this error (code:'+err.code+'): '+err.stack));
},
success: function (){
return done(new Error('wtf'));
}
});
});
});
});
describe('machine that triggers its exits after 0.5 seconds', function (){
describe('with timeout configured for 0.25 seconds', function (){
var machineInstance;
before(function (){
machineInstance = Machine.build({
timeout: 250,
fn: function machineThatNeverTriggersItsExits(inputs, exits, env){
setTimeout(function (){
return exits.success();
}, 500);
}
});
});
it('should call its error exit with a timeout error', function (done){
machineInstance().exec({
error: function (err) {
if (err.code === 'E_MACHINE_TIMEOUT') {
return done();
}
return done(new Error('Expecting Error instance w/ `code` === "E_MACHINE_TIMEOUT", but instead got this error (code:'+err.code+'): '+err.stack));
},
success: function (){
return done(new Error('Should not have called the success exit (should have been prevented by timeout alarm)'));
}
});
});
});
});
});