Changeset View
Changeset View
Standalone View
Standalone View
test/functional/test_framework/test_framework.py
Show All 12 Lines | |||||
import shutil | import shutil | ||||
import sys | import sys | ||||
import tempfile | import tempfile | ||||
import time | import time | ||||
from .authproxy import JSONRPCException | from .authproxy import JSONRPCException | ||||
from . import coverage | from . import coverage | ||||
from .test_node import TestNode | from .test_node import TestNode | ||||
from .mininode import NetworkThread | |||||
from .util import ( | from .util import ( | ||||
assert_equal, | assert_equal, | ||||
check_json_precision, | check_json_precision, | ||||
connect_nodes_bi, | connect_nodes_bi, | ||||
disconnect_nodes, | disconnect_nodes, | ||||
get_datadir_path, | get_datadir_path, | ||||
initialize_datadir, | initialize_datadir, | ||||
MAX_NODES, | MAX_NODES, | ||||
Show All 35 Lines | class BitcoinTestFramework(): | ||||
The __init__() and main() methods should not be overridden. | The __init__() and main() methods should not be overridden. | ||||
This class also contains various public and private helper methods.""" | This class also contains various public and private helper methods.""" | ||||
def __init__(self): | def __init__(self): | ||||
"""Sets test framework defaults. Do not override this method. Instead, override the set_test_params() method""" | """Sets test framework defaults. Do not override this method. Instead, override the set_test_params() method""" | ||||
self.setup_clean_chain = False | self.setup_clean_chain = False | ||||
self.nodes = [] | self.nodes = [] | ||||
self.network_thread = None | |||||
self.mocktime = 0 | self.mocktime = 0 | ||||
self.supports_cli = False | self.supports_cli = False | ||||
self.bind_to_localhost_only = True | self.bind_to_localhost_only = True | ||||
def main(self): | def main(self): | ||||
"""Main function. This should not be overridden by the subclass test scripts.""" | """Main function. This should not be overridden by the subclass test scripts.""" | ||||
parser = argparse.ArgumentParser(usage="%(prog)s [options]") | parser = argparse.ArgumentParser(usage="%(prog)s [options]") | ||||
▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | def main(self): | ||||
# Set up temp directory and start logging | # Set up temp directory and start logging | ||||
if self.options.tmpdir: | if self.options.tmpdir: | ||||
self.options.tmpdir = os.path.abspath(self.options.tmpdir) | self.options.tmpdir = os.path.abspath(self.options.tmpdir) | ||||
os.makedirs(self.options.tmpdir, exist_ok=False) | os.makedirs(self.options.tmpdir, exist_ok=False) | ||||
else: | else: | ||||
self.options.tmpdir = tempfile.mkdtemp(prefix="test") | self.options.tmpdir = tempfile.mkdtemp(prefix="test") | ||||
self._start_logging() | self._start_logging() | ||||
self.log.debug('Setting up network thread') | |||||
self.network_thread = NetworkThread() | |||||
self.network_thread.start() | |||||
success = TestStatus.FAILED | success = TestStatus.FAILED | ||||
try: | try: | ||||
if self.options.usecli and not self.supports_cli: | if self.options.usecli and not self.supports_cli: | ||||
raise SkipTest( | raise SkipTest( | ||||
"--usecli specified but test does not support using CLI") | "--usecli specified but test does not support using CLI") | ||||
self.setup_chain() | self.setup_chain() | ||||
self.setup_network() | self.setup_network() | ||||
Show All 12 Lines | def main(self): | ||||
self.log.exception("Unexpected exception caught during testing") | self.log.exception("Unexpected exception caught during testing") | ||||
except KeyboardInterrupt: | except KeyboardInterrupt: | ||||
self.log.warning("Exiting after keyboard interrupt") | self.log.warning("Exiting after keyboard interrupt") | ||||
if success == TestStatus.FAILED and self.options.pdbonfailure: | if success == TestStatus.FAILED and self.options.pdbonfailure: | ||||
print("Testcase failed. Attaching python debugger. Enter ? for help") | print("Testcase failed. Attaching python debugger. Enter ? for help") | ||||
pdb.set_trace() | pdb.set_trace() | ||||
self.log.debug('Closing down network thread') | |||||
self.network_thread.close() | |||||
if not self.options.noshutdown: | if not self.options.noshutdown: | ||||
self.log.info("Stopping nodes") | self.log.info("Stopping nodes") | ||||
if self.nodes: | if self.nodes: | ||||
self.stop_nodes() | self.stop_nodes() | ||||
else: | else: | ||||
for node in self.nodes: | for node in self.nodes: | ||||
node.cleanup_on_exit = False | node.cleanup_on_exit = False | ||||
self.log.info( | self.log.info( | ||||
▲ Show 20 Lines • Show All 298 Lines • Show Last 20 Lines |