forked from YellowLabTools/YellowLabTools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrunsQueueTest.js
68 lines (50 loc) · 1.79 KB
/
runsQueueTest.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
var should = require('chai').should();
var runsQueue = require('../../lib/server/datastores/runsQueue');
describe('runsQueue', function() {
var queue = new runsQueue();
var aaaRun = null;
var bbbRun = null;
var cccRun = null;
it('should accept a new runId', function(done) {
queue.should.have.a.property('push').that.is.a('function');
aaaRun = queue.push('aaa');
bbbRun = queue.push('bbb');
aaaRun.then(function() {
done();
});
});
it('should return the right positions', function() {
var aaaPosition = queue.getPosition('aaa');
aaaPosition.should.equal(0);
aaaRun.startingPosition.should.equal(0);
var bbbPosition = queue.getPosition('bbb');
bbbPosition.should.equal(1);
bbbRun.startingPosition.should.equal(1);
var cccPosition = queue.getPosition('ccc');
cccPosition.should.equal(-1);
});
it('should refresh runs\' positions', function(done) {
cccRun = queue.push('ccc');
cccRun.progress(function(position) {
position.should.equal(1);
var positionDoubleCheck = queue.getPosition('ccc');
positionDoubleCheck.should.equal(1);
done();
});
queue.remove('aaa');
});
it('should fulfill the promise when first in the line', function(done) {
cccRun.then(function() {
done();
});
queue.remove('bbb');
});
it('should not keep removed runs', function() {
var aaaPosition = queue.getPosition('aaa');
aaaPosition.should.equal(-1);
var bbbPosition = queue.getPosition('bbb');
bbbPosition.should.equal(-1);
var cccPosition = queue.getPosition('ccc');
cccPosition.should.equal(0);
});
});