summary refs log tree commit diff
path: root/tests/utils.py
diff options
context:
space:
mode:
authorDavid Baker <dbkr@matrix.org>2014-08-29 13:24:08 +0100
committerDavid Baker <dbkr@matrix.org>2014-08-29 13:24:08 +0100
commit3e6a19cf0938423b53b17b520bb6c59b9eb4dd06 (patch)
treec36e5b3a253499d6f5b2d44aa954f993c96c5b95 /tests/utils.py
parentChange call signalling messages to be their own types of room events rather t... (diff)
parentShow notifications only when the user is detected as idle (diff)
downloadsynapse-3e6a19cf0938423b53b17b520bb6c59b9eb4dd06.tar.xz
Merge branch 'develop' of github.com:matrix-org/synapse into develop
Diffstat (limited to 'tests/utils.py')
-rw-r--r--tests/utils.py37
1 files changed, 31 insertions, 6 deletions
diff --git a/tests/utils.py b/tests/utils.py
index 98d4f9ed58..37b759febc 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -21,7 +21,7 @@ from synapse.api.events.room import (
     RoomMemberEvent, MessageEvent
 )
 
-from twisted.internet import defer
+from twisted.internet import defer, reactor
 
 from collections import namedtuple
 from mock import patch, Mock
@@ -263,18 +263,43 @@ class DeferredMockCallable(object):
                 d.callback(None)
                 return result
 
-        raise AssertionError("Was not expecting call(%s)" %
+        failure = AssertionError("Was not expecting call(%s)" %
             _format_call(args, kwargs)
         )
 
+        for _, _, d in self.expectations:
+            try:
+                d.errback(failure)
+            except:
+                pass
+
+        raise failure
+
     def expect_call_and_return(self, call, result):
         self.expectations.append((call, result, defer.Deferred()))
 
     @defer.inlineCallbacks
-    def await_calls(self):
-        while self.expectations:
-            (_, _, d) = self.expectations.pop(0)
-            yield d
+    def await_calls(self, timeout=1000):
+        deferred = defer.DeferredList(
+            [d for _, _, d in self.expectations],
+            fireOnOneErrback=True
+        )
+
+        timer = reactor.callLater(
+            timeout/1000,
+            deferred.errback,
+            AssertionError(
+                "%d pending calls left: %s"% (
+                    len([e for e in self.expectations if not e[2].called]),
+                    [e for e in self.expectations if not e[2].called]
+                )
+            )
+        )
+
+        yield deferred
+
+        timer.cancel()
+
         self.calls = []
 
     def assert_had_no_calls(self):