-
Notifications
You must be signed in to change notification settings - Fork 128
/
tests.js
61 lines (56 loc) · 1.49 KB
/
tests.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
const
should = require('should'),
toobusy = require('./');
describe('the library', function() {
it('should export a couple functions', function(done) {
(toobusy).should.be.a('function');
(toobusy.maxLag).should.be.a('function');
(toobusy.shutdown).should.be.a('function');
done();
});
});
describe('maxLag', function() {
it('should default to 70', function(done) {
(toobusy.maxLag()).should.equal(70);
done();
});
it('should throw an exception for values < 10', function(done) {
(function() { toobusy.maxLag(9); }).should.throw;
done();
});
it('should be configurable', function(done) {
(toobusy.maxLag(50)).should.equal(50);
(toobusy.maxLag(10)).should.equal(10);
(toobusy.maxLag()).should.equal(10);
done();
});
});
describe('toobusy()', function() {
it('should return true after a little load', function(done) {
function load() {
if (toobusy()) return done();
var start = new Date();
while ((new Date() - start) < 250) {
for (var i = 0; i < 1e5;) i++;
}
setTimeout(load, 0);
}
load();
});
it('should return a lag value after a little load', function(done) {
function load() {
if (toobusy()) {
var lag = toobusy.lag();
should.exist(lag);
lag.should.be.above(1);
return done();
}
var start = new Date();
while ((new Date() - start) < 250) {
for (var i = 0; i < 1e5;) i++;
}
setTimeout(load, 0);
}
load();
});
});