forked from rerun-io/rerun
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_python_e2e_test.py
executable file
·101 lines (80 loc) · 3.47 KB
/
run_python_e2e_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/env python3
"""
Run some of our python examples, piping their log stream to the rerun process.
This is an end-to-end test for testing:
* Our Python API
* LogMsg encoding/decoding
* Arrow encoding/decoding
* TCP connection
* Data store ingestion
"""
from __future__ import annotations
import argparse
import os
import subprocess
import time
from pathlib import Path
PORT = 9752
def main() -> None:
parser = argparse.ArgumentParser(description="Runs end-to-end tests of select python example.")
parser.add_argument("--no-build", action="store_true", help="Skip building rerun-sdk")
parser.add_argument("--no-install", action="store_true", help="Skip installing the examples")
if parser.parse_args().no_build:
print("Skipping building rerun-sdk - assuming it is already built and up-to-date!")
else:
build_env = os.environ.copy()
if "RUST_LOG" in build_env:
del build_env["RUST_LOG"] # The user likely only meant it for the actual tests; not the setup
print("----------------------------------------------------------")
print("Building rerun-sdk…")
start_time = time.time()
subprocess.Popen(["pixi", "run", "py-build", "--quiet"], env=build_env).wait()
elapsed = time.time() - start_time
print(f"rerun-sdk built in {elapsed:.1f} seconds")
print("")
examples = [
# Trivial examples that don't require weird dependencies, or downloading data
("tests/python/test_api", ["--test", "all"]),
("examples/python/minimal_options", []),
("examples/python/multithreading", []),
("examples/python/plots", []),
]
if not parser.parse_args().no_install:
print("----------------------------------------------------------")
print("Installing examples…")
start_time = time.time()
args = ["pip", "install", "--quiet"]
for example, _ in examples:
# install in editable mode so `__file__` relative paths work
args.extend(["-e", example])
subprocess.run(args, check=True)
elapsed = time.time() - start_time
print(f"pip install in {elapsed:.1f} seconds")
print("")
for example, args in examples:
print("----------------------------------------------------------")
print(f"Testing {example}…\n")
start_time = time.time()
run_example(Path(example).name, args)
elapsed = time.time() - start_time
print(f"{example} done in {elapsed:.1f} seconds")
print()
print()
print("All tests passed successfully!")
def run_example(example: str, extra_args: list[str]) -> None:
env = os.environ.copy()
env["RERUN_STRICT"] = "1"
env["RERUN_PANIC_ON_WARN"] = "1"
cmd = ["python", "-m", "rerun", "--port", str(PORT), "--test-receive"]
rerun_process = subprocess.Popen(cmd, env=env)
time.sleep(0.5) # Wait for rerun server to start to remove a logged warning
cmd = ["python", "-m", example, "--connect", "--addr", f"127.0.0.1:{PORT}"] + extra_args
python_process = subprocess.Popen(cmd, env=env)
print("Waiting for python process to finish…")
returncode = python_process.wait(timeout=30)
assert returncode == 0, f"python process exited with error code {returncode}"
print("Waiting for rerun process to finish…")
returncode = rerun_process.wait(timeout=30)
assert returncode == 0, f"rerun process exited with error code {returncode}"
if __name__ == "__main__":
main()