From 9ed6bb575952268bd484b0448ff1532e4ed3da6d Mon Sep 17 00:00:00 2001 From: pmnoxx Date: Tue, 11 Aug 2020 01:02:29 -0700 Subject: [PATCH] fix test --- nightly/pytest-sanity.txt | 2 + .../sanity/proxy_loose_block_messages.py | 49 +++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 pytest/tests/sanity/proxy_loose_block_messages.py diff --git a/nightly/pytest-sanity.txt b/nightly/pytest-sanity.txt index 423086907cb..120b2515c0a 100644 --- a/nightly/pytest-sanity.txt +++ b/nightly/pytest-sanity.txt @@ -1,4 +1,6 @@ # python sanity tests +pytest sanity/proxy_loose_block_messages.py +pytest sanity/proxy_loose_block_messages.py --features nightly_protocol,nightly_protocol_features pytest sanity/block_production.py pytest sanity/block_production.py --features nightly_protocol,nightly_protocol_features pytest sanity/transactions.py diff --git a/pytest/tests/sanity/proxy_loose_block_messages.py b/pytest/tests/sanity/proxy_loose_block_messages.py new file mode 100644 index 00000000000..e346ff456c4 --- /dev/null +++ b/pytest/tests/sanity/proxy_loose_block_messages.py @@ -0,0 +1,49 @@ +import sys +import time + +sys.path.append('lib') + +from cluster import start_cluster +from peer import * +from proxy import ProxyHandler + +from multiprocessing import Value + +TIMEOUT = 120 +NODES = 9 +ignored_messages = set() +max_height = Value('i', 0) + + +class Handler(ProxyHandler): + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + + async def handle(self, msg, fr, to): + if msg.enum == 'Block': + h = msg.Block.BlockV1.header.BlockHeaderV2.inner_lite.height + if h > max_height.value: + max_height.value = h + print(h, fr, to, msg, msg.Block.enum) + tpl = (h, fr, to) + + if h == NODES - 1 and to < (NODES - 1) / 2 and tpl not in ignored_messages: + ignored_messages.add(tpl) + print("skipping msg from %d to %d" % (fr, to)) + return False + + return True + + +if __name__ == '__main__': + start_cluster(NODES, 0, 1, None, [], {}, message_handler=Handler) + + start = time.time() + while True: + print("max_height", max_height.value) + if time.time() - start >= TIMEOUT or max_height.value > 3 * NODES: + print("DONE") + break + time.sleep(1) + + assert max_height.value > 3 * NODES