test: Adjust some Zcash RPC tests to work with parallel runner

This commit is contained in:
Jack Grigg 2020-11-21 02:35:29 +00:00
parent 01449d8a3d
commit 891fbff5b9
4 changed files with 49 additions and 41 deletions

View File

@ -9,8 +9,9 @@ from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal, assert_greater_than, start_nodes, connect_nodes_bi
import logging
import sys
logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.INFO)
logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.INFO, stream=sys.stdout)
class KeyImportExportTest (BitcoinTestFramework):

View File

@ -11,8 +11,11 @@ from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import (
check_node,
connect_nodes_bi,
start_node,
sync_blocks,
)
import tempfile
from time import sleep
def check_stopped(i, timeout=10):
@ -28,6 +31,17 @@ def check_stopped(i, timeout=10):
class ReorgLimitTest(BitcoinTestFramework):
def setup_nodes(self):
self.log_stderr = tempfile.SpooledTemporaryFile(max_size=2**16)
nodes = []
nodes.append(start_node(0, self.options.tmpdir, stderr=self.log_stderr))
nodes.append(start_node(1, self.options.tmpdir))
nodes.append(start_node(2, self.options.tmpdir))
nodes.append(start_node(3, self.options.tmpdir))
return nodes
def run_test(self):
assert(self.nodes[0].getblockcount() == 200)
assert(self.nodes[2].getblockcount() == 200)
@ -66,19 +80,28 @@ class ReorgLimitTest(BitcoinTestFramework):
assert(self.nodes[0].getblockcount() == 400)
assert(self.nodes[2].getblockcount() == 401)
print("Sync nodes to force a reorg")
connect_nodes_bi(self.nodes, 0, 2)
self.is_network_split = False
# sync_blocks uses RPC calls to wait for nodes to be synced, so don't
# call it here, because it will have a non-specific connection error
# when Node 0 stops. Instead, we explicitly check for the process itself
# to stop.
try:
print("Sync nodes to force a reorg")
connect_nodes_bi(self.nodes, 0, 2)
self.is_network_split = False
# sync_blocks uses RPC calls to wait for nodes to be synced, so don't
# call it here, because it will have a non-specific connection error
# when Node 0 stops. Instead, we explicitly check for the process itself
# to stop.
print("Check Node 0 is no longer running")
assert(check_stopped(0))
print("Check Node 0 is no longer running")
assert(check_stopped(0))
# Dummy stop to enable the test to tear down
self.nodes[0].stop = lambda: True
# Check that node 0 stopped for the expected reason.
self.log_stderr.seek(0)
stderr = self.log_stderr.read().decode('utf-8')
expected_msg = "A block chain reorganization has been detected that would roll back 100 blocks!"
if expected_msg not in stderr:
raise AssertionError("Expected error \"" + expected_msg + "\" not found in:\n" + stderr)
finally:
self.log_stderr.close()
# Dummy stop to enable the test to tear down
self.nodes[0].stop = lambda: True
if __name__ == '__main__':
ReorgLimitTest().main()

View File

@ -28,12 +28,15 @@ length computation (40b5d5e3ea4b602c34c4efaba0b9f6171dddfef5) corrects the issue
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import (assert_equal, assert_true,
assert_start_raises_init_error,
start_nodes, start_node, connect_nodes_bi,
bitcoind_processes,
nuparams, OVERWINTER_BRANCH_ID, SAPLING_BRANCH_ID)
import re
import logging
import sys
logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.INFO, stream=sys.stdout)
HAS_SAPLING = [nuparams(OVERWINTER_BRANCH_ID, 10), nuparams(SAPLING_BRANCH_ID, 15)]
NO_SAPLING = [nuparams(OVERWINTER_BRANCH_ID, 10), nuparams(SAPLING_BRANCH_ID, 150)]
@ -92,35 +95,15 @@ class SaplingRewindTest(BitcoinTestFramework):
# Restart the nodes, reconnect, and sync the network. This succeeds if "-reindex" is passed.
logging.info("Reconnecting the network...")
try:
# expect an exception; the node will refuse to fully start because its last point of
# agreement with the rest of the network was prior to the network upgrade activation
self.nodes[2] = start_node(2, self.options.tmpdir, extra_args=HAS_SAPLING) # + ["-reindex"])
except:
logpath = self.options.tmpdir + "/node2/regtest/debug.log"
found = False
with open(logpath, 'r', encoding='utf8') as f:
for line in f:
# Search for the rollback message in the debug log, and ensure that it has the
# correct expected rollback length.
m = re.search(r'roll back ([0-9]+)', line)
if m is None:
continue
elif m.group(1) == "120":
found = True
break
else:
raise AssertionError("Incorrect rollback length %s found, expected 120." %(m.group(1)))
if not found:
raise AssertionError("Expected rollback message not found in log file.")
# expect an exception; the node will refuse to fully start because its last point of
# agreement with the rest of the network was prior to the network upgrade activation
assert_start_raises_init_error(2, self.options.tmpdir, HAS_SAPLING, "roll back 120")
# restart the node with -reindex to allow the test to complete gracefully,
# otherwise the node shutdown call in test cleanup will throw an error since
# it can't connect
self.nodes[2] = start_node(2, self.options.tmpdir, extra_args=NO_SAPLING + ["-reindex"])
else:
raise AssertionError("Expected node to halt due to excessive rewind length.")
# restart the node with -reindex to allow the test to complete gracefully,
# otherwise the node shutdown call in test cleanup will throw an error since
# it can't connect
self.nodes[2] = start_node(2, self.options.tmpdir, extra_args=NO_SAPLING + ["-reindex"])
if __name__ == '__main__':
SaplingRewindTest().main()

View File

@ -9,8 +9,9 @@ from test_framework.util import assert_equal, assert_greater_than, start_nodes,\
initialize_chain_clean, connect_nodes_bi, wait_and_assert_operationid_status
from functools import reduce
import logging
import sys
logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.INFO)
logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.INFO, stream=sys.stdout)
fee = Decimal('0.0001') # constant (but can be changed within reason)