summary refs log tree commit diff
diff options
context:
space:
mode:
authorPaul "LeoNerd" Evans <paul@matrix.org>2014-12-10 19:26:52 +0000
committerPaul "LeoNerd" Evans <paul@matrix.org>2014-12-10 19:26:52 +0000
commit4551afc6d2f69ae3aa0ac37217fa0a94c0b2d62a (patch)
tree6de7abc773b722ea30bb380862c92b69fa84c313
parentImplement .call_later() in MockClock (diff)
downloadsynapse-4551afc6d2f69ae3aa0ac37217fa0a94c0b2d62a.tar.xz
Implement .cancel_call_later() in MockClock
-rw-r--r--tests/test_test_utils.py18
-rw-r--r--tests/utils.py7
2 files changed, 23 insertions, 2 deletions
diff --git a/tests/test_test_utils.py b/tests/test_test_utils.py
index dcf946fc1a..b42787dd25 100644
--- a/tests/test_test_utils.py
+++ b/tests/test_test_utils.py
@@ -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])
diff --git a/tests/utils.py b/tests/utils.py
index 72843714fd..f9a34748cd 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -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):