-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdag.js
61 lines (53 loc) · 1.3 KB
/
dag.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
describe('dag', function () {
it('should run a set of edges in threads', function (done) {
var deps = [
[ null, 'a' ]
, [ 'a', 'b' ]
, [ 'a', 'c' ]
, [ 'a', 'f' ]
, [ 'd', 'e' ]
, [ 'b', 'd' ]
];
var spy = chai.spy(function (e, next) {
setTimeout(next, 100);
});
dag(deps, 2, spy, function (err) {
should.not.exist(err);
spy.should.have.been.called.exactly(6);
done();
});
});
it('should bail on error', function (done) {
var deps = [
[ 'a', 'b' ]
, [ 'a', 'c' ]
, [ 'd', 'e' ]
, [ 'b', 'd' ]
];
var spy = chai.spy(function (e, next) {
if (e === 'c') return next('err');
setTimeout(next, 100);
});
dag(deps, 2, spy, function (err) {
err.should.equal('err');
spy.should.have.been.called.exactly(3);
done();
});
});
it('should detect cyclical error', function (done) {
var deps = [
[ 'a', 'b' ]
, [ 'b', 'a' ]
];
var spy = chai.spy(function (e, next) {
setTimeout(next, 10);
});
dag(deps, 2, spy, function (err) {
should.exist(err);
err.should.be.instanceof(Error)
.with.property('message', 'b can not come before a');
spy.should.have.not.been.called();
done();
});
});
});