def test_deq_raises_when_stopped(self, config): rq = _RunQueue() rq.await_work.wait = mock.Mock() rq._start_worker_if_needed = mock.Mock() rq.stop = True with pytest.raises(TerminateException): rq.deq() rq.enq(1) with pytest.raises(TerminateException): rq.deq()
def test_queue_is_read_in_correct_order(self, mocktime, config): rq = _RunQueue() t = [100] mocktime.side_effect = lambda: t[0] def advance_time(x): t[0] += x rq.await_work.wait = mock.Mock(side_effect=advance_time) rq._start_worker_if_needed = mock.Mock() rq.enq(2) rq.enq((t[0] + 100, 3)) rq.enq((t[0] - 100, 1)) assert rq.deq() == 1 assert rq.deq() == 2 rq.await_work.wait.assert_not_called() assert rq.deq() == 3 rq.await_work.wait.assert_called_once_with(100)
def test_deq_should_wait_if_queue_is_empty(self, config): rq = _RunQueue() rq.await_work.wait = mock.Mock(side_effect=RuntimeError) with pytest.raises(RuntimeError): rq.deq() rq.await_work.wait.assert_called_once_with()