refactor for Windows testing

This commit is contained in:
meejah
2022-09-01 22:20:07 -06:00
parent 00c785ec76
commit decb36a8f6
2 changed files with 19 additions and 14 deletions

View File

@ -241,12 +241,12 @@ def on_stdin_close(reactor, fn):
when_closed_d.addBoth(on_close)
# we don't need to do anything with this instance because it gets
# hooked into the reactor and thus remembered
StandardIO(
# hooked into the reactor and thus remembered .. but we return it
# for Windows testing purposes.
return StandardIO(
proto=WhenClosed(),
reactor=reactor,
)
return None
def run(config, runApp=twistd.runApp):

View File

@ -643,15 +643,18 @@ class OnStdinCloseTests(SyncTestCase):
def onclose():
called.append(True)
on_stdin_close(reactor, onclose)
proto = on_stdin_close(reactor, onclose)
self.assertEqual(called, [])
print("READERS", reactor.getReaders())
for reader in reactor.getReaders():
reader.loseConnection()
reader.loseConnection()
reactor.advance(1) # ProcessReader does a callLater(0, ..)
# one Unix we can just close all the readers, correctly
# "simulating" a stdin close .. of course, Windows has to be
# difficult
if platform.isWindows():
proto.loseConnection()
else:
for reader in reactor.getReaders():
reader.loseConnection()
reactor.advance(1) # ProcessReader does a callLater(0, ..)
self.assertEqual(called, [True])
@ -668,9 +671,11 @@ class OnStdinCloseTests(SyncTestCase):
on_stdin_close(reactor, onclose)
self.assertEqual(called, [])
for reader in reactor.getReaders():
reader.loseConnection()
reader.loseConnection()
reactor.advance(1) # ProcessReader does a callLater(0, ..)
if platform.isWindows():
proto.loseConnection()
else:
for reader in reactor.getReaders():
reader.loseConnection()
reactor.advance(1) # ProcessReader does a callLater(0, ..)
self.assertEqual(called, [True])