only use fake clocks in tests were required
This commit is contained in:
@@ -22,18 +22,12 @@ describe('Worker class', function () {
|
||||
let mockQueue;
|
||||
|
||||
beforeEach(function () {
|
||||
anchorMoment = moment(anchor);
|
||||
clock = sinon.useFakeTimers(anchorMoment.valueOf());
|
||||
client = new elasticsearchMock.Client();
|
||||
mockQueue = {
|
||||
client: client
|
||||
};
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
clock.restore();
|
||||
});
|
||||
|
||||
describe('invalid construction', function () {
|
||||
it('should throw without a type', function () {
|
||||
const init = () => new Worker(mockQueue);
|
||||
@@ -112,6 +106,15 @@ describe('Worker class', 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 () {
|
||||
const searchSpy = sinon.spy(mockQueue.client, 'search');
|
||||
new Worker(mockQueue, 'test', noop);
|
||||
@@ -154,6 +157,9 @@ describe('Worker class', function () {
|
||||
let updateSpy;
|
||||
|
||||
beforeEach(function () {
|
||||
anchorMoment = moment(anchor);
|
||||
clock = sinon.useFakeTimers(anchorMoment.valueOf());
|
||||
|
||||
params = {
|
||||
index: 'myIndex',
|
||||
type: 'test',
|
||||
@@ -165,6 +171,10 @@ describe('Worker class', function () {
|
||||
updateSpy = sinon.spy(mockQueue.client, 'update');
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
clock.restore();
|
||||
});
|
||||
|
||||
it('should use version on update', function () {
|
||||
worker._claimJob(job);
|
||||
const query = updateSpy.firstCall.args[0];
|
||||
@@ -232,11 +242,19 @@ describe('Worker class', function () {
|
||||
let updateSpy;
|
||||
|
||||
beforeEach(function () {
|
||||
anchorMoment = moment(anchor);
|
||||
clock = sinon.useFakeTimers(anchorMoment.valueOf());
|
||||
|
||||
job = mockQueue.client.get();
|
||||
worker = new Worker(mockQueue, 'test', noop);
|
||||
updateSpy = sinon.spy(mockQueue.client, 'update');
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
clock.restore();
|
||||
});
|
||||
|
||||
|
||||
it('should use version on update', function () {
|
||||
worker._failJob(job);
|
||||
const query = updateSpy.firstCall.args[0];
|
||||
@@ -279,7 +297,6 @@ describe('Worker class', function () {
|
||||
const completedTimestamp = moment(doc.completed_at).valueOf();
|
||||
expect(completedTimestamp).to.be.greaterThan(startTime);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('performing a job', function () {
|
||||
@@ -288,7 +305,6 @@ describe('Worker class', function () {
|
||||
let updateSpy;
|
||||
|
||||
beforeEach(function () {
|
||||
clock.restore();
|
||||
payload = {
|
||||
value: random(0, 100, true)
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user