def test_nondeferred_immediate(self): delay = 0 call_val = 'done' d = calltimeout(self._clock, delay, self._state.nondeferredcall, call_val) self._clock.advance(0) self.assertEqual(d.result, call_val) self.assertTrue(self._state.fired) self.assertFalse(self._clock.getDelayedCalls())
def test_deferred_negative_timeout(self): delay = -1 call_val = 'done' d = calltimeout(self._clock, delay, self._state.deferredcall, call_val, 9) self._clock.advance(10) self.assertEqual(d.result, call_val) self.assertTrue(self._state.fired) self.assertFalse(self._clock.getDelayedCalls())
def test_deferred_delayed(self): delay = 2 call_val = 'done' d = calltimeout(self._clock, delay, self._state.deferredcall, call_val) self._clock.advance(0) self.assertFalse(hasattr(d, 'result')) for _ in range(delay + 1): self._clock.advance(1) self.assertEqual(d.result, call_val) self.assertTrue(self._state.fired)
def test_deferred_cancel(self): delay = 2 call_val = 'done' d = calltimeout(self._clock, delay, self._state.deferredcall, call_val, sys.maxsize >> 1) self._clock.advance(0) d.cancel() self._clock.advance(1) self. assertFailure(d, t_defer.CancelledError) self.assertFalse(self._state.fired) self.assertEqual(len(self._clock.getDelayedCalls()), 0) d.addErrback(lambda _res: None) # silence the unhandled error
def test_deferred_immediate(self): delay = 0 call_val = 'done' d = calltimeout(self._clock, delay, self._state.deferredcall, call_val) self._clock.advance(0) self. assertFailure(d, TimeoutError) self.assertFalse(self._state.fired) self._clock.advance(2) self. assertFailure(d, TimeoutError) self.assertFalse(self._state.fired) self.assertFalse(self._clock.getDelayedCalls()) d.addErrback(lambda _res: None) # silence the unhandled error
def test_nondeferred_delayed(self): delay = 2 call_val = 'done' d = calltimeout(self._clock, delay, self._state.nondeferredcall, call_val) self._clock.advance(0) self.assertEqual(d.result, call_val) self.assertTrue(self._state.fired) for _ in range(delay + 1): self._clock.advance(1) self.assertEqual(d.result, call_val) self.assertTrue(self._state.fired) self.assertFalse(self._clock.getDelayedCalls())