[Twisted-Python] Testing function with delayed calls

Mashiat Sarker Shakkhar mashiat.sarker at gmail.com
Thu Oct 1 14:40:22 MDT 2015


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://twistedmatrix.com/pipermail/twisted-python/attachments/20151001/9bc00592/attachment.html>


More information about the Twisted-Python mailing list