[Dev] Mock Reactor for tests?

Phillip J. Eby pje at telecommunity.com
Tue Jun 7 11:34:32 PDT 2005


At 11:12 AM 6/7/2005 -0700, Heikki Toivonen wrote:
>Phillip J. Eby wrote:
> > I've also investigated the run()/stop() issue, and as far as I can tell
> > this should be a non-issue for tests that run using the Twisted default
> > reactor (which is what Chandler uses).  The reason that you aren't
>
>That's strange, because I was testing with default reactor in a command
>line test app. I just retested and the symptoms are that the (unit test)
>program ends up in infinite loop where it gives timeout errors every now
>and then, and does not respond to Ctrl+C. This is under Cygwin.

Can you send or point me to the test app in question?  The default reactor 
normally disables Ctrl-C (but the testreactor won't, as long as you never 
call reactor.run() directly), but an infinite loop should only happen if 
you don't have anything running that will stop the reactor.


> > reactor.waitFor(deferred, timeout) -- iterate until the deferred
>
>Since I haven't needed to use deferred's in my trivial test cases I'd
>need to figure out how to call this.

Well, if all you want to do is have some code do something and then stop 
the reactor, I could make two methods: reactor.waitFor(seconds) and 
reactor.waitUntil(deferred,timeout).  Then, you could just call waitFor() 
and let your tests do reactor.stop() when done.

By the way, if you are doing assertions in code that is called by the 
reactor, this may be a bit of a problem; the reactor expects to log all 
such errors, and doesn't pass them on anywhere.  So, you would definitely 
need for all your assertions to be in your test method itself (i.e. *after* 
the waitFor/waitUntil)


> > Heikki, does that sound about like what you need for your tests?
>
> From the API description it looks like it would do what I need, with the
>caveat that I need to figure out how to deal with deferreds.
>
>But I think it should go into twisted proper. I have a need for this in
>M2Crypto unit tests, Grant could probably use this for zanshin unit
>tests etc.

I was thinking we'd get it implemented and tested a bit more before 
contributing it, but certainly contributing it would be a good idea.



More information about the Dev mailing list