You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
75 lines
1.9 KiB
75 lines
1.9 KiB
3 years ago
|
import signal
|
||
|
import sys
|
||
2 years ago
|
import toml
|
||
3 years ago
|
|
||
2 years ago
|
from docker import rebuild_images_if_needed, Compose
|
||
|
from pathlib import Path
|
||
|
from utils import *
|
||
3 years ago
|
|
||
1 year ago
|
CARGO_INTEGRATION_TESTS_TOML = Path('../__Cargo_integration.toml')
|
||
2 years ago
|
CLUSTER = Compose()
|
||
3 years ago
|
|
||
|
|
||
2 years ago
|
def fail(msg):
|
||
|
err(msg)
|
||
|
sys.exit(1)
|
||
3 years ago
|
|
||
|
|
||
2 years ago
|
def usage_exit():
|
||
|
usage = f"""Usage:
|
||
2 years ago
|
python {__file__.split('/')[-1]} [--rebuild] [--preserve] [--no-run] [--down]"""
|
||
2 years ago
|
|
||
2 years ago
|
fail(usage)
|
||
|
|
||
|
|
||
1 year ago
|
def create_integration_tests_workspace():
|
||
|
if CARGO_INTEGRATION_TESTS_TOML.exists():
|
||
|
CARGO_INTEGRATION_TESTS_TOML.unlink()
|
||
2 years ago
|
workspace = toml.load('../Cargo.toml')
|
||
1 year ago
|
workspace['workspace']['members'] = ['integration-tests']
|
||
|
with open(CARGO_INTEGRATION_TESTS_TOML, 'w') as fo:
|
||
2 years ago
|
toml.dump(workspace, fo)
|
||
2 years ago
|
|
||
|
|
||
3 years ago
|
def run_tests():
|
||
2 years ago
|
allowed_args = set(["--rebuild", "--preserve", "--no-run", "--release", "--down"])
|
||
2 years ago
|
args = sys.argv[1:]
|
||
|
if not set(args).issubset(allowed_args):
|
||
|
usage_exit()
|
||
|
force_rebuild = '--rebuild' in args
|
||
|
preserve_containers = '--preserve' in args
|
||
|
only_setup_cluster = '--no-run' in args
|
||
2 years ago
|
down_cluster = "--down" in args
|
||
2 years ago
|
|
||
|
def _cleanup():
|
||
|
if not preserve_containers and not only_setup_cluster:
|
||
|
CLUSTER.down()
|
||
1 year ago
|
CARGO_INTEGRATION_TESTS_TOML.unlink(missing_ok=True)
|
||
2 years ago
|
|
||
|
def abort_handler(s, _):
|
||
|
warn(f'Received signal: {s}, gracefully stopping...')
|
||
|
_cleanup()
|
||
|
|
||
2 years ago
|
if down_cluster:
|
||
|
_cleanup()
|
||
|
return
|
||
1 year ago
|
|
||
3 years ago
|
for s in (signal.SIGTERM, signal.SIGINT, signal.SIGHUP):
|
||
|
signal.signal(s, abort_handler)
|
||
|
rebuild_images_if_needed(force_rebuild)
|
||
1 year ago
|
create_integration_tests_workspace()
|
||
3 years ago
|
try:
|
||
2 years ago
|
CLUSTER.up()
|
||
|
CLUSTER.is_alive()
|
||
2 years ago
|
if not only_setup_cluster:
|
||
1 year ago
|
CLUSTER.run('cargo test --test integration-tests')
|
||
3 years ago
|
except Exception as e:
|
||
2 years ago
|
#CLUSTER.print_containers_logs()
|
||
2 years ago
|
fail(e)
|
||
3 years ago
|
finally:
|
||
2 years ago
|
_cleanup()
|
||
3 years ago
|
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
run_tests()
|