diff options
author | gzhao408 <gzhao408@berkeley.edu> | 2020-06-05 15:08:03 -0700 |
---|---|---|
committer | gzhao408 <gzhao408@berkeley.edu> | 2020-06-10 07:28:04 -0700 |
commit | 0474ea25afc65546cbfe5f822c0212bf3e211023 (patch) | |
tree | e04ddda690e9c99e3b3462cc76e583450f310c84 /test | |
parent | 4ef80f0827392a1310ca5a29cc1f8f5ca5d16f95 (diff) |
[test] fix race conditions and test in p2p_filter
-grab mininode_lock for every access to mininode attributes,
otherwise there are race conditions
Diffstat (limited to 'test')
-rwxr-xr-x | test/functional/p2p_filter.py | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/test/functional/p2p_filter.py b/test/functional/p2p_filter.py index fef78a9c40..a1b3f2f052 100755 --- a/test/functional/p2p_filter.py +++ b/test/functional/p2p_filter.py @@ -19,7 +19,7 @@ from test_framework.messages import ( msg_mempool, msg_version, ) -from test_framework.mininode import P2PInterface +from test_framework.mininode import P2PInterface, mininode_lock from test_framework.script import MAX_SCRIPT_ELEMENT_SIZE from test_framework.test_framework import BitcoinTestFramework @@ -36,6 +36,11 @@ class FilterNode(P2PInterface): nFlags=1, ) + def __init__(self): + super().__init__() + self._tx_received = False + self._merkleblock_received = False + def on_inv(self, message): want = msg_getdata() for i in message.inv: @@ -48,10 +53,30 @@ class FilterNode(P2PInterface): self.send_message(want) def on_merkleblock(self, message): - self.merkleblock_received = True + self._merkleblock_received = True def on_tx(self, message): - self.tx_received = True + self._tx_received = True + + @property + def tx_received(self): + with mininode_lock: + return self._tx_received + + @tx_received.setter + def tx_received(self, value): + with mininode_lock: + self._tx_received = value + + @property + def merkleblock_received(self): + with mininode_lock: + return self._merkleblock_received + + @merkleblock_received.setter + def merkleblock_received(self, value): + with mininode_lock: + self._merkleblock_received = value class FilterTest(BitcoinTestFramework): |