Skip to content
Snippets Groups Projects
Commit cf7e7238 authored by Paul "LeoNerd" Evans's avatar Paul "LeoNerd" Evans
Browse files

Have MockClock detect attempts to cancel expired timers, to prevent a repeat of SYN-230

parent c2e7c84e
No related branches found
No related tags found
No related merge requests found
...@@ -138,7 +138,8 @@ class MockClock(object): ...@@ -138,7 +138,8 @@ class MockClock(object):
now = 1000 now = 1000
def __init__(self): 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 = [] self.timers = []
def time(self): def time(self):
...@@ -154,11 +155,16 @@ class MockClock(object): ...@@ -154,11 +155,16 @@ class MockClock(object):
LoggingContext.thread_local.current_context = current_context LoggingContext.thread_local.current_context = current_context
callback() callback()
t = (self.now + delay, wrapped_callback) t = [self.now + delay, wrapped_callback, False]
self.timers.append(t) self.timers.append(t)
return t return t
def cancel_call_later(self, timer): 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] self.timers = [t for t in self.timers if t != timer]
# For unit testing # For unit testing
...@@ -168,11 +174,17 @@ class MockClock(object): ...@@ -168,11 +174,17 @@ class MockClock(object):
timers = self.timers timers = self.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: if self.now >= time:
t[2] = True
callback() callback()
else: else:
self.timers.append((time, callback)) self.timers.append(t)
class SQLiteMemoryDbPool(ConnectionPool, object): class SQLiteMemoryDbPool(ConnectionPool, object):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment