-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathlocalhost_test.py
More file actions
56 lines (45 loc) · 2.15 KB
/
localhost_test.py
File metadata and controls
56 lines (45 loc) · 2.15 KB
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
import Builder
import subprocess
import socket
import sys
import time
import os
class LocalhostTest(Builder.Action):
def start(self, env):
python = sys.executable
venv_path = os.path.join(env.root_dir,'crt','aws-c-http','tests','mock_server', '.venv')
result = env.shell.exec(python, '-m', 'venv', venv_path)
if result.returncode != 0:
print("Could not start a virtual environment. The localhost integration tests will fail.", file=sys.stderr)
return
python = os.path.join(venv_path, "bin", "python")
result = env.shell.exec(python, '-m', 'pip', 'install', 'h11', 'h2', 'trio')
if result.returncode != 0:
print("Could not install python HTTP dependencies. The localhost integration tests will fail.", file=sys.stderr)
return
server_dir = os.path.join(env.root_dir,'crt','aws-c-http','tests','mock_server')
p1 = subprocess.Popen([python, "h2tls_mock_server.py"], cwd=server_dir)
p2 = subprocess.Popen([python, "h2non_tls_server.py"], cwd=server_dir)
p3 = subprocess.Popen([python, "h11mock_server.py"], cwd=server_dir)
# Wait for servers to be ready
ports = [3443, 3280, 8082, 8081]
for port in ports:
for attempt in range(30):
try:
with socket.create_connection(("localhost", port), timeout=1):
print(f"Server on port {port} is ready")
break
except (socket.error, ConnectionRefusedError, OSError):
if attempt == 29:
print(f"ERROR: Server on port {port} failed to start", file=sys.stderr)
time.sleep(1)
def run(self, env):
self.start(env)
env.shell.setenv('AWS_CRT_MEMORY_TRACING', '2')
if os.system("mvn test -DredirectTestOutputToFile=true -DforkCount=0 \
-Daws.crt.memory.tracing=2 \
-Daws.crt.debugnative=true \
-Daws.crt.aws_trace_log_per_test \
-Daws.crt.localhost=true"):
# Failed
actions.append("exit 1")