From b2f4ae857f6bcec132252a75c88605f00fe445a8 Mon Sep 17 00:00:00 2001 From: Joe Fleming Date: Fri, 16 Dec 2016 16:53:22 -0700 Subject: [PATCH] test that the running state prevents searches --- test/src/worker.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/test/src/worker.js b/test/src/worker.js index 0c4df54..bfb7b02 100644 --- a/test/src/worker.js +++ b/test/src/worker.js @@ -185,6 +185,27 @@ describe('Worker class', function () { clock.tick(interval); sinon.assert.calledOnce(searchSpy); }); + + it('should not poll once destroyed', function () { + const worker = new Worker(mockQueue, 'test', noop); + + // move the clock a couple times, test for searches each time + sinon.assert.notCalled(searchSpy); + clock.tick(defaults.interval); + sinon.assert.calledOnce(searchSpy); + clock.tick(defaults.interval); + sinon.assert.calledTwice(searchSpy); + + // destroy the worker, move the clock, make sure another search doesn't happen + worker.destroy(); + clock.tick(defaults.interval); + sinon.assert.calledTwice(searchSpy); + + // manually call job poller, move the clock, make sure another search doesn't happen + worker._startJobPolling(); + clock.tick(defaults.interval); + sinon.assert.calledTwice(searchSpy); + }); }); describe('query for pending jobs', function () {