Mashiat Sarker Shakkhar
2015-10-01 20:40:22 UTC
Hi
I have a function that uses callLater extensively to schedule a number of
different tasks. I don't want to get into the rationale behind such a
design, but here is a contrived example which will help me explain my
problem:
def b():
'''Do some work'''
def c():
'''Do some more work'''
def a(flag):
if flag:
return Reactor.callLater(300, b)
else:
return Reactor. callLater(100, c)
Now I want to test this function. Of course I can't wait for 5 minutes to
ensure that `b` or `c` will indeed be called. What I need is some sort of
mock clock which lets me fast forward time. Does any such thing exist in
Twisted / Trial? Or is there any other approach to test such code?
Regards
Shakkhar
I have a function that uses callLater extensively to schedule a number of
different tasks. I don't want to get into the rationale behind such a
design, but here is a contrived example which will help me explain my
problem:
def b():
'''Do some work'''
def c():
'''Do some more work'''
def a(flag):
if flag:
return Reactor.callLater(300, b)
else:
return Reactor. callLater(100, c)
Now I want to test this function. Of course I can't wait for 5 minutes to
ensure that `b` or `c` will indeed be called. What I need is some sort of
mock clock which lets me fast forward time. Does any such thing exist in
Twisted / Trial? Or is there any other approach to test such code?
Regards
Shakkhar