twisted icon indicating copy to clipboard operation
twisted copied to clipboard

twisted.test.test_task._FakeReactor is an unverified fake with bugs

Open exarkun opened this issue 3 years ago • 0 comments

Describe the incorrect behavior you saw

_FakeReactor is a helper used to test twisted.internet.task.react. It purports to implement IReactorTime and IReactorCore. However, it doesn't.

It uses twisted.internet.task.Clock for its IReactorTime implementation and this is more or less okay, so far as it goes. It brings its own novel implementation of IReactorCore and this is missing pieces and has errors in the pieces it does have:

  • running is not given the correct value at the correct times. It becomes True as soon as run is called but in a real reactor it does not change this way until the during startup phase.
  • Similarly, it becomes False as soon as stop is called. A real reactor does not change this way until the during shutdown phase.
  • It does not implement any after phases.

These are the errors and omissions that are either readily apparent by reading the implementation or which came up while working on #11650.

Most of the functionality here does not actually involve I/O (and at worst we have Clock for the pieces might). Instead of having an unverified fake of some pure functions, let's just share the pure functions between implementation and tests.

I suggest factoring these pieces out of ReactorBase so they can be shared and then using them to replace _FakeReactor.

exarkun avatar Sep 16 '22 18:09 exarkun