-
Notifications
You must be signed in to change notification settings - Fork 9
/
run_tests.py
102 lines (72 loc) · 2.4 KB
/
run_tests.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
102
#!/usr/bin/env python3
import subprocess
import threading
from datetime import datetime, timedelta
from pathlib import Path
TEST_RUNNING_MSG = """
---------------------------------------------------------
Running Unit Tests...
---------------------------------------------------------
"""
TEST_SUCC_MSG = """
---------------------------------------------------------
Unit Tests Completed Successfully
---------------------------------------------------------
"""
TEST_FAIL_MSG = """
---------------------------------------------------------
Unit Tests Failed
---------------------------------------------------------
"""
lock = threading.Lock()
tests_ran_successfully = True
class TestThread(threading.Thread):
def __init__(self, shard_count: int, shard_index: int):
threading.Thread.__init__(self)
self.shard_count = shard_count
self.shard_index = shard_index
def run(self):
global tests_ran_successfully
global lock
lock.acquire()
print(f"Starting shard {self.shard_index + 1} / {self.shard_count}")
lock.release()
result = subprocess.run(
f"{test_file} --shard-count {self.shard_count} --shard-index {self.shard_index}",
shell=True,
capture_output=True,
text=True,
)
lock.acquire()
print(result.stdout)
print(result.stderr)
tests_ran_successfully = tests_ran_successfully and (result.returncode == 0)
lock.release()
if __name__ == "__main__":
lock_file = Path(__file__).parent / "test_err_cnt.log.lock"
test_file = Path(__file__).parent / "build" / "test" / "test"
if lock_file.exists():
print(
f"{lock_file} already exists. Probably from previously terminated test run."
)
print("Removing the lock file before continuing tests!")
lock_file.unlink()
print(TEST_RUNNING_MSG)
threads = []
TEST_SHARDS = 8
for idx in range(TEST_SHARDS):
threads += [TestThread(TEST_SHARDS, idx)]
start_time = datetime.now()
for thread in threads:
thread.start()
for thread in threads:
thread.join()
end_time = datetime.now()
test_duration = end_time - start_time
print(f"Test execution took {test_duration} (h:min:s)")
if tests_ran_successfully:
print(TEST_SUCC_MSG)
exit(0)
else:
print(TEST_FAIL_MSG)
exit(1)