Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
pmnoxx authored and pmnoxx committed Nov 12, 2021
1 parent 6d8eee6 commit 9ed6bb5
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
2 changes: 2 additions & 0 deletions nightly/pytest-sanity.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
49 changes: 49 additions & 0 deletions pytest/tests/sanity/proxy_loose_block_messages.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 9ed6bb5

Please sign in to comment.