Debian Codegraph @

crt/aws-c-http/.builder/action/local-server-setup.py

raw symbols SCIP
1 """
2 Setup local server for tests
3 """
4
5 import Builder
6
7 import os
8 import sys
9 import subprocess
10 import atexit
11
12
13 class LocalServerSetup(Builder.Action):
14 """
15 Set up this machine for running the local h2 server test.
16 To run the local server related test, use `--cmake-extra=-DENABLE_LOCALHOST_INTEGRATION_TESTS=ON` from builder.
17 Not running local server tests for every CI as it takes a while.
18
19 This action should be run in the 'pre_build_steps' or 'build_steps' stage.
20 """
21
22 def run(self, env):
23 if not env.project.needs_tests(env):
24 print("Skipping local server setup because tests disabled for project")
25 return
26
27 self.env = env
28 python_path = sys.executable
29 # Install dependency for mock server.
30 # Okay to fail, and if it fails, you will know when you enable the localhost tests.
31 # We don't need it to succeed on every platform we have.
32 result = self.env.shell.exec(python_path,
33 '-m', 'pip', 'install', 'h11', 'h2', 'trio')
34 if result.returncode != 0:
35 print(
36 "Could not install python HTTP/2 server." +
37 " The localhost integration tests will fail if you run them.", file=sys.stderr)
38 return
39
40 base_dir = os.path.dirname(os.path.realpath(__file__))
41 dir = os.path.join(base_dir, "..", "..", "tests", "mock_server")
42 os.chdir(dir)
43
44 p_server = subprocess.Popen([python_path, "h2tls_mock_server.py"])
45 p_non_tls_server = subprocess.Popen([python_path, "h2non_tls_server.py"])
46 p_h11_server = subprocess.Popen([python_path, "h11mock_server.py"])
47
48 @atexit.register
49 def close_local_server():
50 p_server.terminate()
51 p_non_tls_server.terminate()