check-mirroring: Try receiving zephyrs multiple times to avoid large queues.

(imported from commit 08c08df46794cd89db19748c3d5adfa4097de4cb)
This commit is contained in:
Tim Abbott 2012-12-11 17:38:34 -05:00
parent 47313467b1
commit aba1ca871c

View file

@ -174,6 +174,24 @@ def gen_keys(key_dict):
gen_keys(zhkeys) gen_keys(zhkeys)
gen_keys(hzkeys) gen_keys(hzkeys)
notices = []
# We check for new zephyrs multiple times, to avoid filling the zephyr
# receive queue with 30+ messages, which might result in messages
# being dropped.
def receive_zephyrs():
while True:
try:
notice = zephyr.receive(block=False)
except Exception:
logging.exception("Exception receiving zephyrs:")
notice = None
if notice is None:
break
if notice.opcode != "":
continue
notices.append(notice)
logger.info("Starting sending messages!") logger.info("Starting sending messages!")
# Send zephyrs # Send zephyrs
zsig = "Timothy Good Abbott" zsig = "Timothy Good Abbott"
@ -183,6 +201,8 @@ for key, (stream, test) in zhkeys.items():
else: else:
zwrite_args = ["zwrite", "-n", "-s", zsig, "-c", stream, "-i", "test"] zwrite_args = ["zwrite", "-n", "-s", zsig, "-c", stream, "-i", "test"]
send_zephyr(zwrite_args, str(key)) send_zephyr(zwrite_args, str(key))
receive_zephyrs()
logger.info("Sent Zephyr messages!") logger.info("Sent Zephyr messages!")
# Send Humbugs # Send Humbugs
@ -200,37 +220,26 @@ for key, (stream, test) in hzkeys.items():
"content": str(key), "content": str(key),
"to": stream, "to": stream,
}) })
receive_zephyrs()
logger.info("Sent Humbug messages!") logger.info("Sent Humbug messages!")
failed = False
# Normally messages manage to forward through in under 3 seconds, but # Normally messages manage to forward through in under 3 seconds, but
# sleep 10 to give a safe margin since the messages do need to do 2 # sleep 10 to give a safe margin since the messages do need to do 2
# round trips. This alert is for correctness, not performance, and so # round trips. This alert is for correctness, not performance, and so
# we want it to reliably alert only when messages aren't being # we want it to reliably alert only when messages aren't being
# delivered at all. # delivered at all.
time.sleep(10) time.sleep(10)
receive_zephyrs()
logger.info("Starting receiving messages!") logger.info("Starting receiving messages!")
# receive humbugs # receive humbugs
messages = humbug_client.get_messages({'last': str(max_message_id)})['messages'] messages = humbug_client.get_messages({'last': str(max_message_id)})['messages']
logger.info("Received Humbug messages!") logger.info("Finished receiving Humbug messages!")
# receive zephyrs receive_zephyrs()
notices = [] logger.info("Finished receiving Zephyr messages!")
while True:
try:
notice = zephyr.receive(block=False)
except Exception:
logging.exception("Exception receiving zephyrs:")
notice = None
if notice is None:
break
if notice.opcode != "":
continue
notices.append(notice)
logger.info("Received Zephyr messages!")
all_keys = set(zhkeys.keys() + hzkeys.keys()) all_keys = set(zhkeys.keys() + hzkeys.keys())
def process_keys(content_list): def process_keys(content_list):