def test_cancelled_jobs_arent_executed(redis, loop): """Cancelling jobs.""" q = Queue() job = yield from q.enqueue(touch_a_mock) # Here, we cancel the job, so the sentinel file may not be created yield from redis.delete(job.key) w = Worker([q]) yield from w.work(burst=True, loop=loop) assert not (yield from q.count) # Should not have created evidence of execution assert not mock.call_count mock.reset_mock()
def test_timeouts(set_loop): """Worker kills jobs after timeout.""" q = Queue() w = Worker([q]) # Put it on the queue with a timeout value res = yield from q.enqueue( touch_a_mock_after_timeout, args=(4,), timeout=1) assert not mock.call_count yield from w.work(burst=True) assert not mock.call_count # TODO: Having to do the manual refresh() here is really ugly! yield from res.refresh() assert 'JobTimeoutException' in as_text(res.exc_info) mock.reset_mock()
def test_suspend_worker_execution(redis, loop): """Test Pause Worker Execution.""" q = Queue() w = Worker([q]) yield from q.enqueue(touch_a_mock) yield from suspend(redis) yield from w.work(burst=True, loop=loop) assert (yield from q.count) == 1 assert not mock.call_count yield from resume(redis) yield from w.work(burst=True, loop=loop) assert not (yield from q.count) assert mock.call_count mock.reset_mock()