diff options
author | David Baker <dave@matrix.org> | 2015-01-22 17:46:16 +0000 |
---|---|---|
committer | David Baker <dave@matrix.org> | 2015-01-22 17:46:16 +0000 |
commit | 5c6189ea3eb36409c57cd269a8931dda8f30e6ec (patch) | |
tree | 6a6217c76e23359e2edcebd1020b4807f18b3073 /tests/utils.py | |
parent | Oops: second part of commit dc938606 (diff) | |
parent | Merge pull request #30 from matrix-org/client_api_restructure (diff) | |
download | synapse-5c6189ea3eb36409c57cd269a8931dda8f30e6ec.tar.xz |
Merge branch 'develop' into pushers
Conflicts: synapse/rest/__init__.py
Diffstat (limited to 'tests/utils.py')
-rw-r--r-- | tests/utils.py | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/tests/utils.py b/tests/utils.py index 731e03f517..97fa8d8181 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -138,7 +138,8 @@ class MockClock(object): now = 1000 def __init__(self): - # list of tuples of (absolute_time, callback) in no particular order + # list of lists of [absolute_time, callback, expired] in no particular + # order self.timers = [] def time(self): @@ -154,11 +155,16 @@ class MockClock(object): LoggingContext.thread_local.current_context = current_context callback() - t = (self.now + delay, wrapped_callback) + t = [self.now + delay, wrapped_callback, False] self.timers.append(t) + return t def cancel_call_later(self, timer): + if timer[2]: + raise Exception("Cannot cancel an expired timer") + + timer[2] = True self.timers = [t for t in self.timers if t != timer] # For unit testing @@ -168,11 +174,17 @@ class MockClock(object): timers = self.timers self.timers = [] - for time, callback in timers: + for t in timers: + time, callback, expired = t + + if expired: + raise Exception("Timer already expired") + if self.now >= time: + t[2] = True callback() else: - self.timers.append((time, callback)) + self.timers.append(t) class SQLiteMemoryDbPool(ConnectionPool, object): |