[Dev] Mock Reactor for tests?
Phillip J. Eby
pje at telecommunity.com
Tue Jun 7 21:00:33 PDT 2005
At 08:03 PM 6/7/2005 -0700, Heikki Toivonen wrote:
>The test_twisted_wrapper() could be done using the testreactor we have
>discussed in this thread with mocket. But if it would be possible to
>start and stop the testreactor as many times as I wanted I would just
>replace the reactor with testreactor, along with the deferred sample you
>showed, and I should be all set. So I think I actually answered my own
>question.
Okay, so how should we move forward? I drafted a testreactor module
earlier today, but it's not checked in and I don't have any tests for it
yet. I could add some simple self-tests tomorrow, and check it in, and
then you could experiment with running some tests against it, and let me
know how it works. What do you think?
With regard to the specific test code you're talking about, though, the
testreactor would have to run in real time, not simulated time, because I
wrote it assuming that the select() calls would always succeed with zero
delay (due to being loopbacks). In the test code you pointed me to,
there's an external server so there would actually be a need to run with
wall clock time. So, if that's what you're talking about (running real
socket tests with a restartable reactor), then I need to add a new API,
maybe something like reactor.useRealTime() and
useSimulatedTime(). Currently, the testreactor I wrote always uses
simulated time. Also, I'm probably going to have to restrict the mode
switching such that it never makes time run backwards... which will be
interesting. Probably I should just make it so that you can only set the
clock mode once per test, and then the clock can't run backwards within
that test, even if it appears to run backwards across tests. Yeah, I can
do that.
More information about the Dev
mailing list