-
Notifications
You must be signed in to change notification settings - Fork 1
/
integr_test.py
106 lines (85 loc) · 2.88 KB
/
integr_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
102
103
104
105
106
from subprocess import Popen, DEVNULL, PIPE, run, TimeoutExpired
from threading import Thread
import sys
import shlex
import os
import time
def print_to_strerr(msg):
sys.stderr.buffer.write(msg)
sys.stderr.buffer.flush()
def print_to_stdout(msg):
sys.stdout.buffer.write(msg)
sys.stdout.buffer.flush()
def start_node():
node = Popen(['./target/release/gn-node', '--dev', '--enable-offchain-indexing', 'true'],
stderr=PIPE, stdout=DEVNULL)
start = time.time()
line = b""
while b"Running JSON-RPC WS" not in line:
line = node.stderr.readline()
print_to_stdout(line)
if int(time.time() - start) == 10:
print_to_strerr(b"Node startup timeout, exiting...")
os._exit(111)
return node
def start_oracle():
oracle = Popen(['./target/release/gn-cli', 'oracle', '--activate'],
stderr=PIPE, stdout=DEVNULL)
start = time.time()
line = b""
while line == b"":
line = oracle.stderr.readline()
if int(time.time() - start) == 10:
print_to_strerr(b"Oracle startup timeout, exiting...")
os._exit(222)
print_to_stdout(line)
return oracle
def monitor_oracle(oracle, node):
retcode = monitor_process(oracle)
if retcode != 0:
node.kill()
while node.poll() is None:
pass
os._exit(retcode)
def monitor_process(process):
while True:
line = process.stderr.readline()
if line != b"":
print_to_strerr(line)
retcode = process.poll()
if retcode is not None:
return retcode
def run_tests(*commands, timeout=300):
try:
for cmd in commands:
test = run(shlex.split(cmd), timeout=timeout)
print("Test finished with return code:", test.returncode)
return test.returncode
except TimeoutExpired:
print_to_strerr(b"Test timeout expired\n")
return -1
# NOTE: this script is a rushed abomination of bodged half solutions, but it does the job
def main():
try:
node = start_node()
command = "./target/release/gn-cli sudo oracle register"
run_tests(command, timeout=90)
oracle = start_oracle()
oracle_monitor = Thread(target=monitor_oracle, args=(oracle, node,))
oracle_monitor.start()
command = "cargo run --release --example guild --features external-oracle -- "
status = run_tests(command + "join",
command + "token",
command + "eth",
timeout=90)
node.send_signal(15)
oracle.send_signal(15)
while node.poll() is None or oracle.poll() is None:
pass
os._exit(status)
except KeyboardInterrupt:
node.kill()
oracle.kill()
while node.poll() is None or oracle.poll() is None:
pass
main()