summary refs log tree commit diff
path: root/tests/util/test_linearizer.py
diff options
context:
space:
mode:
authorRichard van der Hoff <1389908+richvdh@users.noreply.github.com>2018-07-20 14:44:02 +0100
committerGitHub <noreply@github.com>2018-07-20 14:44:02 +0100
commitff48ab8527fb51c338ae79c583583f000263c453 (patch)
tree899ddb3c55d95502cd1d6b93a8f3b78edb8a7e79 /tests/util/test_linearizer.py
parentMerge pull request #3571 from matrix-org/rav/limiter_fixes (diff)
parentChangelog (diff)
downloadsynapse-ff48ab8527fb51c338ae79c583583f000263c453.tar.xz
Merge pull request #3572 from matrix-org/rav/linearizer_cancellation
Test and fix support for cancellation in Linearizer
Diffstat (limited to 'tests/util/test_linearizer.py')
-rw-r--r--tests/util/test_linearizer.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/util/test_linearizer.py b/tests/util/test_linearizer.py
index c9563124f9..4729bd5a0a 100644
--- a/tests/util/test_linearizer.py
+++ b/tests/util/test_linearizer.py
@@ -17,6 +17,7 @@
 from six.moves import range
 
 from twisted.internet import defer, reactor
+from twisted.internet.defer import CancelledError
 
 from synapse.util import Clock, logcontext
 from synapse.util.async import Linearizer
@@ -112,3 +113,33 @@ class LinearizerTestCase(unittest.TestCase):
         d6 = limiter.queue(key)
         with (yield d6):
             pass
+
+    @defer.inlineCallbacks
+    def test_cancellation(self):
+        linearizer = Linearizer()
+
+        key = object()
+
+        d1 = linearizer.queue(key)
+        cm1 = yield d1
+
+        d2 = linearizer.queue(key)
+        self.assertFalse(d2.called)
+
+        d3 = linearizer.queue(key)
+        self.assertFalse(d3.called)
+
+        d2.cancel()
+
+        with cm1:
+            pass
+
+        self.assertTrue(d2.called)
+        try:
+            yield d2
+            self.fail("Expected d2 to raise CancelledError")
+        except CancelledError:
+            pass
+
+        with (yield d3):
+            pass