-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathrun_all.py
271 lines (240 loc) · 7.96 KB
/
run_all.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
import os
import subprocess
import sys
import tempfile
import traceback
drivers = [
{
"name": "go",
"repo": "https://github.com/neo4j/neo4j-go-driver.git",
"art": [
" XXX XX ",
"X X X",
"X XX X X",
"X X X X",
"X X X X",
" XX XX ",
],
"branch-translation": {
"4.0": "4.2",
"4.1": "4.2",
}
},
{
"name": "javascript",
"repo": "https://github.com/neo4j/neo4j-javascript-driver.git",
"art": [
" X XXX",
" X X ",
" X XXX ",
"X X X",
"X X X",
" XX XXX ",
],
"branch-translation": {
# TODO: until a 5.0 branch has been created
"5.0": "4.4",
}
},
{
"name": "python",
"repo": "https://github.com/neo4j/neo4j-python-driver.git",
"art": [
"XXX X X",
"X X X X",
"X X X X",
"X X XX ",
"X XX ",
"X XX ",
],
},
{
"name": "python",
"repo": "https://github.com/neo4j/neo4j-python-driver.git",
"art": [
"XXX X X XX XXX X X X X XXX",
"X X X X X X X X X XX X XX ",
"X X X X XXXX XXX X X X XX X ",
"X X XX X X X XX X XX X ",
"X XX X X X XX X X XX ",
"X XX X X XXX XX X X XXX",
],
"extra-env": {
"TEST_BACKEND_SERVER": "async"
},
},
{
"name": "java",
"repo": "https://github.com/neo4j/neo4j-java-driver.git",
"art": [
" X XX ",
" X X X",
" X XXXX",
"X X X X",
"X X X X",
" XX X X",
],
},
{
"name": "java",
"repo": "https://github.com/neo4j/neo4j-java-driver.git",
"art": [
" X XX XX XXX X X X X XXX",
" X X X X X X X X XX X XX ",
" X XXXX XXXX XXX X X X XX X ",
"X X X X X X X XX X XX X ",
"X X X X X X X XX X X XX ",
" XX X X X X XXX XX X X XXX",
],
"extra-env": {
"TEST_BACKEND_SERVER": "async"
},
},
{
"name": "java",
"repo": "https://github.com/neo4j/neo4j-java-driver.git",
"art": [
" X XX XXX X X",
" X X X X X X X",
" X XXXX XXX XX ",
"X X X X X XX X X",
"X X X X X X X X",
" XX X X X X X X",
],
"extra-env": {
"TEST_BACKEND_SERVER": "reactive"
},
},
{
"name": "dotnet",
"repo": "https://github.com/neo4j/neo4j-dotnet-driver.git",
"art": [
" X X",
" XX X",
" X XX",
" X XX",
" XX X X",
" XX X X",
],
"branch-translation": {
# TODO: until a 5.0 branch has been created
"5.0": "4.4",
}
}
]
def patched_process_run(*popenargs,
input=None, # noqa: A002
capture_output=False, timeout=None, check=False,
**kwargs):
"""
Copy of subprocess.run with increased process._sigint_wait_secs.
This gives testkit enough time to clean the docker "mess" it made.
"""
if input is not None:
if kwargs.get("stdin") is not None:
raise ValueError("stdin and input arguments may not both be used.")
kwargs["stdin"] = subprocess.PIPE
if capture_output:
if (kwargs.get("stdout") is not None
or kwargs.get("stderr") is not None):
raise ValueError("stdout and stderr arguments may not be used "
"with capture_output.")
kwargs["stdout"] = subprocess.PIPE
kwargs["stderr"] = subprocess.PIPE
with subprocess.Popen(*popenargs, **kwargs) as process:
process._sigint_wait_secs = 10
try:
stdout, stderr = process.communicate(input, timeout=timeout)
except subprocess.TimeoutExpired as exc:
process.kill()
if subprocess._mswindows:
# Windows accumulates the output in a single blocking
# read() call run on child threads, with the timeout
# being done in a join() on those threads. communicate()
# _after_ kill() is required to collect that and add it
# to the exception.
exc.stdout, exc.stderr = process.communicate()
else:
# POSIX _communicate already populated the output so
# far into the TimeoutExpired exception.
process.wait()
raise
except BaseException:
# Including KeyboardInterrupt, communicate handled that.
process.kill()
# We don't call process.wait() as .__exit__ does that for us.
raise
retcode = process.poll()
if check and retcode:
raise subprocess.CalledProcessError(retcode, process.args,
output=stdout, stderr=stderr)
return subprocess.CompletedProcess(process.args, retcode, stdout, stderr)
def setup_environment():
temp_path = tempfile.gettempdir()
driver_repo_path = os.path.join(temp_path, "driver")
# cleanup environment
os.makedirs(temp_path, exist_ok=True)
rmdir(driver_repo_path)
branch = os.environ.get("TEST_DRIVER_BRANCH", "4.4")
return driver_repo_path, branch
def rmdir(dir_):
try:
subprocess.run(["rm", "-fr", dir_])
except FileNotFoundError:
pass
def translate_branch(driver, branch):
return driver.get("branch-translation", {}).get(branch, branch)
def clone_repo(driver, branch, path):
subprocess.run(["git", "clone", "--branch", branch,
driver.get("repo"), path], check=True)
def update_environment(driver, repo_path):
os.environ["TEST_DRIVER_REPO"] = os.path.abspath(repo_path)
os.environ["TEST_DRIVER_NAME"] = driver.get("name")
os.environ["ARTIFACTS_DIR"] = os.path.join(".", "artifacts",
driver.get("name"))
os.environ.update(driver.get("extra-env", {}))
def run():
arguments = sys.argv[1:]
try:
patched_process_run(["python3", "main.py"] + arguments, check=True)
return True
except subprocess.CalledProcessError:
if os.environ.get("TEST_RUN_ALL_DRIVERS", "").lower() \
in ("true", "y", "yes", "1", "on"):
traceback.print_exc()
return False
else:
raise
def print_art(driver, branch, scale):
print("")
print(
"Testing %s (%s) branch %s" % (driver["name"], driver["repo"], branch)
)
print("")
art = driver.get("art", False)
if not art:
return
print("")
for line in art:
for _ in range(scale):
for char in line:
print(char * scale, end="")
print("")
print("")
sys.stdout.flush()
def main():
driver_repo_path, branch = setup_environment()
success = True
for driver in drivers:
print_art(driver, branch, 2)
translated_branch = translate_branch(driver, branch)
try:
clone_repo(driver, translated_branch, driver_repo_path)
update_environment(driver, driver_repo_path)
success = run() and success
finally:
rmdir(driver_repo_path)
if not success:
sys.exit("One or more drivers caused failing tests.")
if __name__ == "__main__":
main()