This repository has been archived by the owner on Nov 6, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 64
/
test_timeout.js
73 lines (56 loc) · 2.04 KB
/
test_timeout.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
71
72
73
var assert = require('assert');
var helpers = require('./helpers');
var Queue = require('../lib/queue');
var sinon = require('sinon');
var Worker = require('../lib/worker');
describe('Timeout', function () {
var queue, handler, worker, failed;
beforeEach(function () {
queue = new Queue({ db: helpers.db });
handler = sinon.spy(function (params, callback) {
// Don't call the callback, let it timeout
});
failed = sinon.spy();
worker = new Worker([queue], { interval: 10 });
worker.register({ timeout: handler });
worker.on('failed', failed);
});
afterEach(function (done) {
queue.collection.remove({}, done);
});
describe('worker processing job with a timeout', function () {
beforeEach(function (done) {
queue.enqueue('timeout', {}, { timeout: 10 }, done);
});
beforeEach(function (done) {
helpers.flushWorker(worker, done);
});
it('calls the handler once', function () {
assert.equal(handler.callCount, 1);
});
it('emits `failed` event once', function () {
assert.equal(failed.callCount, 1);
});
it('updates the job status', function () {
var job = failed.lastCall.args[0];
assert.equal(job.status, 'failed');
assert.equal(job.error, 'timeout');
});
});
describe('worker processing job with a timeout and retries', function () {
beforeEach(function (done) {
queue.enqueue('timeout', {}, { timeout: 10, attempts: { count: 3 }}, done);
});
beforeEach(function (done) {
helpers.flushWorker(worker, done);
});
it('calls the handler three times', function () {
assert.equal(handler.callCount, 3);
});
it('updates the job status', function () {
var job = failed.lastCall.args[0];
assert.equal(job.status, 'failed');
assert.equal(job.error, 'timeout');
});
});
});