only use fake clocks in tests were required

This commit is contained in:
2016-05-03 11:36:55 -07:00
parent f725824c5f
commit f722bbf5e1

View File

@@ -22,18 +22,12 @@ describe('Worker class', function () {
let mockQueue; let mockQueue;
beforeEach(function () { beforeEach(function () {
anchorMoment = moment(anchor);
clock = sinon.useFakeTimers(anchorMoment.valueOf());
client = new elasticsearchMock.Client(); client = new elasticsearchMock.Client();
mockQueue = { mockQueue = {
client: client client: client
}; };
}); });
afterEach(function () {
clock.restore();
});
describe('invalid construction', function () { describe('invalid construction', function () {
it('should throw without a type', function () { it('should throw without a type', function () {
const init = () => new Worker(mockQueue); const init = () => new Worker(mockQueue);
@@ -112,6 +106,15 @@ describe('Worker class', function () {
}); });
describe('searching for jobs', function () { describe('searching for jobs', function () {
beforeEach(() => {
anchorMoment = moment(anchor);
clock = sinon.useFakeTimers(anchorMoment.valueOf());
});
afterEach(() => {
clock.restore();
});
it('should start polling for jobs after interval', function () { it('should start polling for jobs after interval', function () {
const searchSpy = sinon.spy(mockQueue.client, 'search'); const searchSpy = sinon.spy(mockQueue.client, 'search');
new Worker(mockQueue, 'test', noop); new Worker(mockQueue, 'test', noop);
@@ -154,6 +157,9 @@ describe('Worker class', function () {
let updateSpy; let updateSpy;
beforeEach(function () { beforeEach(function () {
anchorMoment = moment(anchor);
clock = sinon.useFakeTimers(anchorMoment.valueOf());
params = { params = {
index: 'myIndex', index: 'myIndex',
type: 'test', type: 'test',
@@ -165,6 +171,10 @@ describe('Worker class', function () {
updateSpy = sinon.spy(mockQueue.client, 'update'); updateSpy = sinon.spy(mockQueue.client, 'update');
}); });
afterEach(() => {
clock.restore();
});
it('should use version on update', function () { it('should use version on update', function () {
worker._claimJob(job); worker._claimJob(job);
const query = updateSpy.firstCall.args[0]; const query = updateSpy.firstCall.args[0];
@@ -232,11 +242,19 @@ describe('Worker class', function () {
let updateSpy; let updateSpy;
beforeEach(function () { beforeEach(function () {
anchorMoment = moment(anchor);
clock = sinon.useFakeTimers(anchorMoment.valueOf());
job = mockQueue.client.get(); job = mockQueue.client.get();
worker = new Worker(mockQueue, 'test', noop); worker = new Worker(mockQueue, 'test', noop);
updateSpy = sinon.spy(mockQueue.client, 'update'); updateSpy = sinon.spy(mockQueue.client, 'update');
}); });
afterEach(() => {
clock.restore();
});
it('should use version on update', function () { it('should use version on update', function () {
worker._failJob(job); worker._failJob(job);
const query = updateSpy.firstCall.args[0]; const query = updateSpy.firstCall.args[0];
@@ -279,7 +297,6 @@ describe('Worker class', function () {
const completedTimestamp = moment(doc.completed_at).valueOf(); const completedTimestamp = moment(doc.completed_at).valueOf();
expect(completedTimestamp).to.be.greaterThan(startTime); expect(completedTimestamp).to.be.greaterThan(startTime);
}); });
}); });
describe('performing a job', function () { describe('performing a job', function () {
@@ -288,7 +305,6 @@ describe('Worker class', function () {
let updateSpy; let updateSpy;
beforeEach(function () { beforeEach(function () {
clock.restore();
payload = { payload = {
value: random(0, 100, true) value: random(0, 100, true)
}; };