mirror of
https://git.anonymousland.org/anonymousland/synapse-product.git
synced 2024-10-01 08:25:44 -04:00
Implement .cancel_call_later() in MockClock
This commit is contained in:
parent
38da9884e7
commit
4551afc6d2
@ -50,3 +50,21 @@ class MockClockTestCase(unittest.TestCase):
|
||||
self.clock.advance_time(5)
|
||||
|
||||
self.assertTrue(invoked[1])
|
||||
|
||||
def test_cancel_later(self):
|
||||
invoked = [0, 0]
|
||||
|
||||
def _cb0():
|
||||
invoked[0] = 1
|
||||
t0 = self.clock.call_later(10, _cb0)
|
||||
|
||||
def _cb1():
|
||||
invoked[1] = 1
|
||||
t1 = self.clock.call_later(20, _cb1)
|
||||
|
||||
self.clock.cancel_call_later(t0)
|
||||
|
||||
self.clock.advance_time(30)
|
||||
|
||||
self.assertFalse(invoked[0])
|
||||
self.assertTrue(invoked[1])
|
||||
|
@ -152,10 +152,13 @@ class MockClock(object):
|
||||
def wrapped_callback():
|
||||
LoggingContext.thread_local.current_context = current_context
|
||||
callback()
|
||||
self.timers.append((self.now + delay, wrapped_callback))
|
||||
|
||||
t = (self.now + delay, wrapped_callback)
|
||||
self.timers.append(t)
|
||||
return t
|
||||
|
||||
def cancel_call_later(self, timer):
|
||||
raise NotImplementedError("Oopsie")
|
||||
self.timers = [t for t in self.timers if t != timer]
|
||||
|
||||
# For unit testing
|
||||
def advance_time(self, secs):
|
||||
|
Loading…
Reference in New Issue
Block a user