[Dev] Mock Reactor for tests?
Phillip J. Eby
pje at telecommunity.com
Mon Jun 6 14:22:38 PDT 2005
At 12:58 PM 6/6/2005 -0700, Heikki Toivonen wrote:
>Brian Kirsch wrote:
> > I am not sure if we really need the mock reactor. Twisted provides very
> > good trial test support for creating local loopbacks between
>
>There was recent discussion on twisted mailinglist about trial, and the
>consensus seems to be that it is broken and you should not use it if you
>can help it. Search mailinglist for summary line: "Hanging test cases
>(Was: Evangelism notes...)".
>
>Bob Ippolito quote: "Trial is horribly, horribly broken by design and
>it's really just an accident that it works at all."
That would help explain the comments and typos I saw in the source. :)
> > Twisted clients and Twisted servers. What is the issue with run and stop
> > of a reactor? To my knowledge this should not be a problem.
>
>I haven't tracked down the exact issues, but when I tried to call
>run()/stop() more than once in a test program it just did not work. I
>don't remember the errors, but I could rerun them if you like. Also I
>seem to recall it was mentioned on twisted mailinglist that you only
>ever call reactor.run()/stop() once in a program, period.
I seem to recall that in the thread I cited previously, someone was saying
you should use crash() for unit tests, rather than stop(). I suspect this
is because stop() shuts down a lot of things that crash() does not.
> > Also if all the unit tests were running in the same process why would
> > you need to stop and start the reactor?
>
>If that was the case, but the tests should also be runnable standalone,
>in which case they do need to start and stop the reactor at least once
>for the module. But it seems like the reactor has a member 'running' so
>the module could see if the reactor has been started already and adjust
>it's behavior accordingly.
>
>Unfortunately not being able to call run() (which blocks until stop() is
>called) makes unit testing harder. Which gets us back to the "horribly,
>horribly broken" trial.
Even if you do have run(), if you're using a "real" reactor your tests can
easily hang unless you have some kind of timeout mechanism. A mock reactor
can have additional methods for testing, like runUntil(deferred, timeOut)
or iterate(simulated_duration).
More information about the Dev
mailing list