From 0c1d8825473d4f8b7a9fe29b2d6366dbedccd558 Mon Sep 17 00:00:00 2001 From: David Wilson Date: Mon, 12 Aug 2019 11:38:24 +0100 Subject: [PATCH] issue #613: must await 'exit' and 'disconnect' in wait=False test --- tests/router_test.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/tests/router_test.py b/tests/router_test.py index a9ad5ae1..1cde016d 100644 --- a/tests/router_test.py +++ b/tests/router_test.py @@ -434,12 +434,21 @@ class ShutdownTest(testlib.RouterMixin, testlib.TestCase): l1 = self.router.local() pid = l1.call(os.getpid) - conn = self.router.stream_by_id(l1.context_id).conn + strm = self.router.stream_by_id(l1.context_id) exitted = mitogen.core.Latch() - mitogen.core.listen(conn.proc, 'exit', exitted.put) + + # It is possible for Process 'exit' signal to fire immediately during + # processing of Stream 'disconnect' signal, so we must wait for both, + # otherwise ChannelError below will return 'respondent context has + # disconnected' rather than 'no route', because RouteMonitor hasn't run + # yet and the Receiver caught Context 'disconnect' signal instead of a + # dead message. + mitogen.core.listen(strm.conn.proc, 'exit', exitted.put) + mitogen.core.listen(strm, 'disconnect', exitted.put) l1.shutdown(wait=False) exitted.get() + exitted.get() e = self.assertRaises(OSError, lambda: os.waitpid(pid, 0))