Changeset View
Changeset View
Standalone View
Standalone View
test/functional/test_framework/test_framework.py
Show All 12 Lines | |||||
import random | import random | ||||
import shutil | import shutil | ||||
import sys | import sys | ||||
import tempfile | import tempfile | ||||
import time | import time | ||||
from typing import Optional | from typing import Optional | ||||
from .authproxy import JSONRPCException | from .authproxy import JSONRPCException | ||||
from .avatools import get_proof_ids | |||||
from . import coverage | from . import coverage | ||||
from .p2p import NetworkThread | from .p2p import NetworkThread | ||||
from .test_node import TestNode | from .test_node import TestNode | ||||
from .util import ( | from .util import ( | ||||
assert_equal, | assert_equal, | ||||
check_json_precision, | check_json_precision, | ||||
connect_nodes, | connect_nodes, | ||||
disconnect_nodes, | disconnect_nodes, | ||||
▲ Show 20 Lines • Show All 544 Lines • ▼ Show 20 Lines | def sync_mempools(self, nodes=None, wait=1, timeout=60, | ||||
# Check that each peer has at least one connection | # Check that each peer has at least one connection | ||||
assert (all([len(x.getpeerinfo()) for x in rpc_connections])) | assert (all([len(x.getpeerinfo()) for x in rpc_connections])) | ||||
time.sleep(wait) | time.sleep(wait) | ||||
raise AssertionError("Mempool sync timed out after {}s:{}".format( | raise AssertionError("Mempool sync timed out after {}s:{}".format( | ||||
timeout, | timeout, | ||||
"".join("\n {!r}".format(m) for m in pool), | "".join("\n {!r}".format(m) for m in pool), | ||||
)) | )) | ||||
def sync_proofs(self, nodes=None, wait=1, timeout=60): | |||||
""" | |||||
Wait until everybody has the same proofs in their proof pools | |||||
""" | |||||
rpc_connections = nodes or self.nodes | |||||
timeout = int(timeout * self.options.timeout_factor) | |||||
stop_time = time.time() + timeout | |||||
while time.time() <= stop_time: | |||||
nodes_proofs = [set(get_proof_ids(r)) for r in rpc_connections] | |||||
if nodes_proofs.count(nodes_proofs[0]) == len(rpc_connections): | |||||
return | |||||
# Check that each peer has at least one connection | |||||
assert (all([len(x.getpeerinfo()) for x in rpc_connections])) | |||||
time.sleep(wait) | |||||
raise AssertionError("Proofs sync timed out after {}s:{}".format( | |||||
timeout, | |||||
"".join("\n {!r}".format(m) for m in nodes_proofs), | |||||
)) | |||||
def sync_all(self, nodes=None): | def sync_all(self, nodes=None): | ||||
self.sync_blocks(nodes) | self.sync_blocks(nodes) | ||||
self.sync_mempools(nodes) | self.sync_mempools(nodes) | ||||
# Private helper methods. These should not be accessed by the subclass | # Private helper methods. These should not be accessed by the subclass | ||||
# test scripts. | # test scripts. | ||||
def _start_logging(self): | def _start_logging(self): | ||||
▲ Show 20 Lines • Show All 173 Lines • Show Last 20 Lines |