From ca34a2a02f0152d43cfc4d42c010e596ffc06981 Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Mon, 26 Nov 2012 16:29:44 -0500 Subject: [PATCH] check-mirroring: Fix some issues with startup process timing. It seems that check-mirroring was reporting a lot of spurious failures due to it sometimes taking more than 3 seconds for the setup phase of check-mirroring's receive path to run. So fix this: (1) Wait a bit more than 3 seconds for the receiver to subscribe to messages (2) Subscribe to Humbug messages before forking (we can't do this with zephyr.init() because python-zephyr gets totally messed up if you use it from multiple processes with a shared initialization) (3) Get rid of the old time.sleep(0.x) values that were intended to make messages arrive in order -- since we're now checking that messages correctly arrived using set(), they aren't needed. (4) Use a single request to subscribe to both zephyr classes we need to subscribe to (saves 1 RTT). (imported from commit d96aef05405ce43e9a4a549de189da9a2e393875) --- bots/check-mirroring | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/bots/check-mirroring b/bots/check-mirroring index 2701f3f..0c80c70 100755 --- a/bots/check-mirroring +++ b/bots/check-mirroring @@ -60,10 +60,12 @@ def print_humbug(message): print message["type"], message['sender_email'], \ message['display_recipient'], message['content'] +max_message_id = humbug_client.get_profile()['max_message_id'] + child_pid = os.fork() if child_pid == 0: # Run the humbug => zephyr mirror in the child - time.sleep(3) + time.sleep(5) result = humbug_client.send_message({ "type": "private", "content": str(hzkey1), @@ -74,7 +76,6 @@ if child_pid == 0: print "key1 send error:" print result - time.sleep(0.2) result = humbug_client.send_message({ "type": "stream", "subject": "test", @@ -88,7 +89,6 @@ if child_pid == 0: if options.verbose: print "Sent Humbug messages!" - time.sleep(0.5) import zephyr try: @@ -104,7 +104,6 @@ if child_pid == 0: cls="message", instance="personal") zeph.setmessage("%s\0%s" % (zsig, zhkey1)) zeph.send() - time.sleep(0.2) zeph = zephyr.ZNotice(sender=mit_user, auth=True, cls="tabbott-nagios-test", instance="test") @@ -113,23 +112,18 @@ if child_pid == 0: if options.verbose: print "Sent Zephyr messages!" - else: failed = False import zephyr try: zephyr.init() - subs = zephyr.Subscriptions() - subs.add(('message', 'personal', 'tabbott/extra@ATHENA.MIT.EDU')) - subs.add(('tabbott-nagios-test', '*', '*')) + zephyr._z.subAll([('message', 'personal', 'tabbott/extra@ATHENA.MIT.EDU'), + ('tabbott-nagios-test', '*', '*')]) except IOError, e: if "SERVNAK received" in e: print "SERVNAK received, punting rest of test" print_status_and_exit(0) - - max_message_id = humbug_client.get_profile()['max_message_id'] - time.sleep(20) if options.verbose: print "Receiving messages!"