__main__.py
1 """ 2 Entry point for `arti_rpc_tests`. 3 4 LIMITATIONS: (TODO RPC) 5 - Only one instance of this process can run at once, 6 since it tries to bind to a hardwired SOCKS tcp port. 7 8 BEHAVIOR: 9 - Launches arti 10 - Waits for it to be reachable via RPC. 11 - Runs a series of tests against arti or its RPC connection 12 - Tries to shut down Arti cleanly. 13 14 ENVIRONMENT VARIABLES: 15 16 - ARTI: Path to the arti binary to use. 17 - LIBARTI_RPC_CLIENT_CORE: Path to the Arti RPC library to use. 18 (Consumed by `arti_rpc` package.) 19 - ARTI_RPC_TEST_DIR: Location at which Arti will store files 20 and look for cache. (This is reused across runs unless 21 explicitly deleted.) 22 23 ARGUMENTS: 24 25 -- --arti-dir=DIR: override ARTI_RPC_TEST_DIR. 26 """ 27 28 from arti_rpc_tests import context, runner 29 30 import argparse 31 import logging 32 import os 33 import sys 34 import time 35 36 from pathlib import Path 37 38 ###### 39 # Find arguments and environment. 40 41 parser = argparse.ArgumentParser() 42 parser.add_argument( 43 "--arti-dir", help="Location for Arti proxy storage and config", type=Path 44 ) 45 args = parser.parse_args() 46 47 arti_binary = Path(os.environ["ARTI"]) 48 if args.arti_dir is not None: 49 test_dir = args.arti_dir 50 else: 51 test_dir = Path(os.environ["ARTI_RPC_TEST_DIR"]) 52 53 # TODO: Take this from the command line once it has arguments 54 testfilter = runner.TestFilter() 55 56 logging.basicConfig(level=logging.INFO) 57 58 ###### 59 # Clear variables that have special meaning for arti_rpc_client_core. 60 61 for var in [ 62 "ARTI_RPC_CONNECT_PATH", 63 "ARTI_RPC_CONNECT_PATH_OVERRIDE", 64 "ARTI_RPC_FORCE_SYSTEM_ARTI", 65 ]: 66 try: 67 del os.environ[var] 68 except KeyError: 69 pass 70 71 ##### 72 # Build a test process 73 test_context = context.TestContext(arti_binary, test_dir) 74 test_context.launch_arti() 75 76 ##### 77 # Run the selected tests. 78 79 okay = runner.run_tests(testfilter, runner.all_modules(), test_context) 80 81 ##### 82 # Wait a bit, then shut down arti. 83 # 84 # (We'll remove the delay once we have a few more tests.) 85 86 if test_context.arti_process is not None: 87 SHUTDOWN_DELAY = 3 88 print(f"Waiting {SHUTDOWN_DELAY} seconds...") 89 time.sleep(SHUTDOWN_DELAY) # TODO: remove this once the tests are nontrivial. 90 print("Shutting down...") 91 test_context.arti_process.close(gently=True) 92 93 if not okay: 94 sys.exit(1)