def test_message_ack_timing_keeper_edge_cases(): matk = MessageAckTimingKeeper() # No measurements -> empty report assert matk.generate_report() == [] # Unknown messages must be ignored processed = Processed(MessageID(999), make_signature()) matk.finalize_message(processed) assert matk.generate_report() == [] reveal_secret = RevealSecret(MessageID(1), make_signature(), make_secret()) matk.add_message(reveal_secret) # In flight messages are not included in reports assert matk.generate_report() == []
def test_message_ack_timing_keeper(): matk = MessageAckTimingKeeper() matk.add_message(RevealSecret(MessageID(1), make_signature(), make_secret())) gevent.sleep(0.05) matk.finalize_message(Processed(MessageID(1), make_signature())) assert len(matk._durations) == 1 assert 0.05 <= matk._durations[0] <= 0.06 # Set duration to a fixed value matk._durations[0] = 0.05 report = matk.generate_report() assert len(report) == 1 assert report == [0.05]