From decb36a8f6f4d755b51c6f2b2e624d77dcf31899 Mon Sep 17 00:00:00 2001 From: meejah Date: Thu, 1 Sep 2022 22:20:07 -0600 Subject: [PATCH] refactor for Windows testing --- src/allmydata/scripts/tahoe_run.py | 6 +++--- src/allmydata/test/test_runner.py | 27 ++++++++++++++++----------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/allmydata/scripts/tahoe_run.py b/src/allmydata/scripts/tahoe_run.py index 68578a2a1..63dc351b1 100644 --- a/src/allmydata/scripts/tahoe_run.py +++ b/src/allmydata/scripts/tahoe_run.py @@ -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): diff --git a/src/allmydata/test/test_runner.py b/src/allmydata/test/test_runner.py index 74d7ac59f..fc3ed9618 100644 --- a/src/allmydata/test/test_runner.py +++ b/src/allmydata/test/test_runner.py @@ -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])