aboutsummaryrefslogtreecommitdiff
path: root/test/functional/example_test.py
diff options
context:
space:
mode:
authorJohn Newbery <john@johnnewbery.com>2017-12-07 13:40:39 -0500
committerJohn Newbery <john@johnnewbery.com>2017-12-11 09:17:21 -0500
commit34e08b3510c64e35fc51327562d15d938f4b656e (patch)
treec6f09d62e3a5da99daa809c942e7f8bd7c474558 /test/functional/example_test.py
parent74e64f24b8cb701379b34442f21332361dcc91f9 (diff)
[tests] Fix network threading in functional tests
assumevalid.py, example_test.py and p2p-acceptblocks.py add p2p_connections after the NetworkThread has been started. This isn't permitted. Fix test to restart the network thread when adding new connections. p2p-leaktest.py had a potential race condition if the NetworkThread hadn't terminated by the time we tried to restart it.
Diffstat (limited to 'test/functional/example_test.py')
-rwxr-xr-xtest/functional/example_test.py10
1 files changed, 9 insertions, 1 deletions
diff --git a/test/functional/example_test.py b/test/functional/example_test.py
index c9c5c6fc4b..12be685ecf 100755
--- a/test/functional/example_test.py
+++ b/test/functional/example_test.py
@@ -21,6 +21,7 @@ from test_framework.mininode import (
mininode_lock,
msg_block,
msg_getdata,
+ network_thread_join,
network_thread_start,
)
from test_framework.test_framework import BitcoinTestFramework
@@ -131,7 +132,7 @@ class ExampleTest(BitcoinTestFramework):
def run_test(self):
"""Main test logic"""
- # Create a P2P connection to one of the nodes
+ # Create P2P connections to two of the nodes
self.nodes[0].add_p2p_connection(BaseNode())
# Start up network handling in another thread. This needs to be called
@@ -188,7 +189,14 @@ class ExampleTest(BitcoinTestFramework):
connect_nodes(self.nodes[1], 2)
self.log.info("Add P2P connection to node2")
+ # We can't add additional P2P connections once the network thread has started. Disconnect the connection
+ # to node0, wait for the network thread to terminate, then connect to node2. This is specific to
+ # the current implementation of the network thread and may be improved in future.
+ self.nodes[0].disconnect_p2ps()
+ network_thread_join()
+
self.nodes[2].add_p2p_connection(BaseNode())
+ network_thread_start()
self.nodes[2].p2p.wait_for_verack()
self.log.info("Wait for node2 reach current tip. Test that it has propagated all the blocks to us")