twisted.test.test_task._FakeReactor is an unverified fake with bugs
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:
runningis not given the correct value at the correct times. It becomesTrueas soon asrunis called but in a real reactor it does not change this way until theduringstartupphase.- Similarly, it becomes
Falseas soon asstopis called. A real reactor does not change this way until theduringshutdownphase. - It does not implement any
afterphases.
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.