tests: fix more DisconnectTest raciness.

issue510
David Wilson 6 years ago
parent 1c24a13560
commit cd6486b0e9

@ -31,8 +31,25 @@ def wait_for_child(pid, timeout=1.0):
@mitogen.core.takes_econtext @mitogen.core.takes_econtext
def call_func_in_sibling(ctx, econtext): def call_func_in_sibling(ctx, econtext, sync_sender):
ctx.call(time.sleep, 99999) recv = ctx.call_async(time.sleep, 99999)
sync_sender.send(None)
recv.get().unpickle()
def wait_for_empty_output_queue(sync_recv, context):
# wait for sender to submit their RPC. Since the RPC is sent first, the
# message sent to this sender cannot arrive until we've routed the RPC.
sync_recv.get()
router = context.router
broker = router.broker
while True:
# Now wait for the RPC to exit the output queue.
stream = router.stream_by_id(context.context_id)
if broker.defer_sync(lambda: stream.pending_bytes()) == 0:
return
time.sleep(0.1)
class GetDefaultRemoteNameTest(testlib.TestCase): class GetDefaultRemoteNameTest(testlib.TestCase):
@ -353,12 +370,17 @@ class DisconnectTest(testlib.RouterMixin, testlib.TestCase):
self.router.stream_by_id(c1.context_id).auth_id = mitogen.context_id self.router.stream_by_id(c1.context_id).auth_id = mitogen.context_id
c1.call(mitogen.parent.upgrade_router) c1.call(mitogen.parent.upgrade_router)
recv = c1.call_async(call_func_in_sibling, c2) sync_recv = mitogen.core.Receiver(self.router)
recv = c1.call_async(call_func_in_sibling, c2,
sync_sender=sync_recv.to_sender())
wait_for_empty_output_queue(sync_recv, c2)
c2.shutdown(wait=True) c2.shutdown(wait=True)
e = self.assertRaises(mitogen.core.CallError, e = self.assertRaises(mitogen.core.CallError,
lambda: recv.get().unpickle()) lambda: recv.get().unpickle())
s = 'mitogen.core.ChannelError: ' + self.router.respondent_disconnect_msg s = 'mitogen.core.ChannelError: ' + self.router.respondent_disconnect_msg
self.assertTrue(e.args[0].startswith(s)) self.assertTrue(e.args[0].startswith(s), str(e))
def test_far_sibling_disconnected(self): def test_far_sibling_disconnected(self):
# God mode: child of child notices child of child of parent has # God mode: child of child notices child of child of parent has
@ -373,8 +395,13 @@ class DisconnectTest(testlib.RouterMixin, testlib.TestCase):
self.router.stream_by_id(c1.context_id).auth_id = mitogen.context_id self.router.stream_by_id(c1.context_id).auth_id = mitogen.context_id
c11.call(mitogen.parent.upgrade_router) c11.call(mitogen.parent.upgrade_router)
recv = c11.call_async(call_func_in_sibling, c22) sync_recv = mitogen.core.Receiver(self.router)
recv = c11.call_async(call_func_in_sibling, c22,
sync_sender=sync_recv.to_sender())
wait_for_empty_output_queue(sync_recv, c22)
c22.shutdown(wait=True) c22.shutdown(wait=True)
e = self.assertRaises(mitogen.core.CallError, e = self.assertRaises(mitogen.core.CallError,
lambda: recv.get().unpickle()) lambda: recv.get().unpickle())
s = 'mitogen.core.ChannelError: ' + self.router.respondent_disconnect_msg s = 'mitogen.core.ChannelError: ' + self.router.respondent_disconnect_msg

Loading…
Cancel
Save