Skip to content

Commit 36b5acb

Browse files
committed
PYTHON-5207 Convert mod_wsgi tests to use the new test runner
1 parent 5e055ee commit 36b5acb

File tree

11 files changed

+183
-101
lines changed

11 files changed

+183
-101
lines changed

.evergreen/config.yml

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -227,17 +227,6 @@ functions:
227227
args:
228228
- ${DRIVERS_TOOLS}/.evergreen/atlas_data_lake/run-mongohouse-image.sh
229229

230-
"run mod_wsgi tests":
231-
- command: subprocess.exec
232-
type: test
233-
params:
234-
include_expansions_in_env: [MOD_WSGI_VERSION, MOD_WSGI_EMBEDDED, "PYTHON_BINARY"]
235-
working_dir: "src"
236-
binary: bash
237-
args:
238-
- .evergreen/scripts/run-with-env.sh
239-
- .evergreen/scripts/run-mod-wsgi-tests.sh
240-
241230
"run doctests":
242231
- command: subprocess.exec
243232
type: test
@@ -411,40 +400,6 @@ tasks:
411400
TEST_NAME: index_management
412401
AUTH: "auth"
413402

414-
- name: "mod-wsgi-standalone"
415-
tags: ["mod_wsgi"]
416-
commands:
417-
- func: "run server"
418-
vars:
419-
TOPOLOGY: "server"
420-
- func: "run mod_wsgi tests"
421-
422-
- name: "mod-wsgi-replica-set"
423-
tags: ["mod_wsgi"]
424-
commands:
425-
- func: "run server"
426-
vars:
427-
TOPOLOGY: "replica_set"
428-
- func: "run mod_wsgi tests"
429-
430-
- name: "mod-wsgi-embedded-mode-standalone"
431-
tags: ["mod_wsgi"]
432-
commands:
433-
- func: "run server"
434-
- func: "run mod_wsgi tests"
435-
vars:
436-
MOD_WSGI_EMBEDDED: "1"
437-
438-
- name: "mod-wsgi-embedded-mode-replica-set"
439-
tags: ["mod_wsgi"]
440-
commands:
441-
- func: "run server"
442-
vars:
443-
TOPOLOGY: "replica_set"
444-
- func: "run mod_wsgi tests"
445-
vars:
446-
MOD_WSGI_EMBEDDED: "1"
447-
448403
- name: "no-server"
449404
tags: ["no-server"]
450405
commands:

.evergreen/generated_configs/tasks.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,48 @@ tasks:
775775
TEST_NAME: load_balancer
776776
tags: [load-balancer, noauth, nossl]
777777

778+
# Mod wsgi tests
779+
- name: mod-wsgi-standalone
780+
commands:
781+
- func: run server
782+
vars:
783+
TOPOLOGY: standalone
784+
- func: run tests
785+
vars:
786+
TEST_NAME: mod_wsgi
787+
SUB_TEST_NAME: standalone
788+
tags: [mod_wsgi]
789+
- name: mod-wsgi-replica-set
790+
commands:
791+
- func: run server
792+
vars:
793+
TOPOLOGY: replica-set
794+
- func: run tests
795+
vars:
796+
TEST_NAME: mod_wsgi
797+
SUB_TEST_NAME: standalone
798+
tags: [mod_wsgi]
799+
- name: mod-wsgi-embedded-modestandalone
800+
commands:
801+
- func: run server
802+
vars:
803+
TOPOLOGY: standalone
804+
- func: run tests
805+
vars:
806+
TEST_NAME: mod_wsgi
807+
SUB_TEST_NAME: embedded-mode
808+
tags: [mod_wsgi]
809+
- name: mod-wsgi-embedded-modereplica-set
810+
commands:
811+
- func: run server
812+
vars:
813+
TOPOLOGY: replica-set
814+
- func: run tests
815+
vars:
816+
TEST_NAME: mod_wsgi
817+
SUB_TEST_NAME: embedded-mode
818+
tags: [mod_wsgi]
819+
778820
# Ocsp tests
779821
- name: test-ocsp-ecdsa-valid-cert-server-does-not-staple
780822
commands:

.evergreen/scripts/generate_config.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -892,6 +892,24 @@ def create_oidc_tasks():
892892
return tasks
893893

894894

895+
def create_mod_wsgi_tasks():
896+
tasks = []
897+
for test, topology in product(["standalone", "embedded-mode"], ["standalone", "replica-set"]):
898+
if test == "standalone":
899+
task_name = "mod-wsgi-"
900+
else:
901+
task_name = "mod-wsgi-embedded-mode"
902+
task_name += topology
903+
server_vars = dict(TOPOLOGY=topology)
904+
server_func = FunctionCall(func="run server", vars=server_vars)
905+
vars = dict(TEST_NAME="mod_wsgi", SUB_TEST_NAME=test)
906+
test_func = FunctionCall(func="run tests", vars=vars)
907+
tags = ["mod_wsgi"]
908+
commands = [server_func, test_func]
909+
tasks.append(EvgTask(name=task_name, tags=tags, commands=commands))
910+
return tasks
911+
912+
895913
def _create_ocsp_task(algo, variant, server_type, base_task_name):
896914
file_name = f"{algo}-basic-tls-ocsp-{variant}.json"
897915

.evergreen/scripts/mod_wsgi_tester.py

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
from __future__ import annotations
2+
3+
import os
4+
import sys
5+
import time
6+
import urllib.error
7+
import urllib.request
8+
from pathlib import Path
9+
from shutil import which
10+
11+
from utils import LOGGER, ROOT, run_command, write_env
12+
13+
14+
def make_request(url, timeout=10):
15+
for _ in range(int(timeout)):
16+
try:
17+
urllib.request.urlopen(url) # noqa: S310
18+
return
19+
except urllib.error.HTTPError:
20+
pass
21+
time.sleep(1)
22+
raise TimeoutError(f"Failed to access {url}")
23+
24+
25+
def setup_mod_wsgi(sub_test_name: str) -> None:
26+
env = os.environ.copy()
27+
if sub_test_name == "embedded":
28+
env["MOD_WSGI_CONF"] = "mod_wsgi_test_embedded.conf"
29+
elif sub_test_name == "standalone":
30+
env["MOD_WSGI_CONF"] = "mod_wsgi_test.conf"
31+
else:
32+
raise ValueError("mod_wsgi sub test must be either 'standalone' or 'embedded'")
33+
apache = which("apache")
34+
if not apache and Path("/usr/lib/apache2/mpm-prefork/apache2").exists():
35+
apache = "/usr/lib/apache2/mpm-prefork/apache2"
36+
if apache:
37+
apache_config = "apache24ubuntu161404.conf"
38+
else:
39+
apache = which("httpd")
40+
if not apache:
41+
raise ValueError("Could not find apache2 or httpd")
42+
apache_config = "apache22amazon.conf"
43+
python_version = ".".join(str(val) for val in sys.version_info[:2])
44+
mod_wsgi_version = 4
45+
env[
46+
"MOD_WSGI_SO"
47+
] = f"/opt/python/mod_wsgi/python_version/{python_version}/mod_wsgi_version/{mod_wsgi_version}/mod_wsgi.so"
48+
env["PYTHONHOME"] = f"/opt/python/{python_version}"
49+
env["PROJECT_DIRECTORY"] = project_directory = str(ROOT)
50+
write_env("APACHE", apache)
51+
write_env("APACHE_CONFIG", apache_config)
52+
uri1 = f"http://localhost:8080/interpreter1{project_directory}"
53+
write_env("TEST_URI1", uri1)
54+
uri2 = f"http://localhost:8080/interpreter2{project_directory}"
55+
write_env("TEST_URI2", uri2)
56+
run_command(f"{apache} -k start -f {ROOT}/test/mod_wsgi_test/{apache_config}")
57+
58+
# Wait for the endpoints to be available.
59+
try:
60+
make_request(uri1, 10)
61+
make_request(uri2, 10)
62+
except Exception as e:
63+
LOGGER.error(Path("error_log").read_text())
64+
raise e
65+
66+
67+
def test_mod_wsgi() -> None:
68+
sys.path.insert(0, ROOT)
69+
from test.mod_wsgi_test.test_client import main, parse_args
70+
71+
uri1 = os.environ["TEST_URI1"]
72+
uri2 = os.environ["TEST_URI2"]
73+
args = f"-n 25000 -t 100 parallel {uri1} {uri2}"
74+
try:
75+
main(*parse_args(args))
76+
77+
args = f"-n 25000 serial {uri1} {uri2}"
78+
main(*parse_args(args))
79+
except Exception as e:
80+
LOGGER.error(Path("error_log").read_text())
81+
raise e
82+
83+
84+
def teardown_mod_wsgi() -> None:
85+
apache = os.environ["APACHE"]
86+
apache_config = os.environ["APACHE_CONFIG"]
87+
run_command(f"{apache} -k stop -f {ROOT}/test/mod_wsgi_test/{apache_config}")
88+
89+
90+
if __name__ == "__main__":
91+
setup_mod_wsgi()

.evergreen/scripts/run-mod-wsgi-tests.sh

Lines changed: 0 additions & 53 deletions
This file was deleted.

.evergreen/scripts/run_tests.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,13 @@ def run() -> None:
100100
if TEST_PERF:
101101
start_time = datetime.now()
102102

103+
# Run mod_wsgi tests using the script.
104+
if TEST_NAME == "mod_wsgi":
105+
from mod_wsgi_tester import test_mod_wsgi
106+
107+
test_mod_wsgi()
108+
return
109+
103110
# Send kms tests to run remotely.
104111
if TEST_NAME == "kms" and SUB_TEST_NAME in ["azure", "gcp"]:
105112
from kms_tester import test_kms_send_to_remote

.evergreen/scripts/setup_tests.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,11 @@ def handle_test_env() -> None:
251251
cmd = f'bash "{DRIVERS_TOOLS}/.evergreen/run-load-balancer.sh" start'
252252
run_command(cmd)
253253

254+
if test_name == "mod_wsgi":
255+
from mod_wsgi_tester import setup_mod_wsgi
256+
257+
setup_mod_wsgi(sub_test_name)
258+
254259
if test_name == "ocsp":
255260
if sub_test_name:
256261
os.environ["OCSP_SERVER_TYPE"] = sub_test_name

.evergreen/scripts/teardown_tests.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,10 @@
4444
elif TEST_NAME == "auth_aws" and sys.platform != "darwin":
4545
run_command(f"bash {DRIVERS_TOOLS}/.evergreen/auth_aws/teardown.sh")
4646

47+
# Tear down mog_wsgi if applicable.
48+
elif TEST_NAME == "mod_wsgi":
49+
from mod_wsgi_tester import teardown_mod_wsgi
50+
51+
teardown_mod_wsgi()
52+
4753
LOGGER.info(f"Tearing down tests of type '{TEST_NAME}'... done.")

.evergreen/scripts/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class Distro:
5050
}
5151

5252
# Tests that require a sub test suite.
53-
SUB_TEST_REQUIRED = ["auth_aws", "auth_oidc", "kms"]
53+
SUB_TEST_REQUIRED = ["auth_aws", "auth_oidc", "kms", "mod_wsgi"]
5454

5555

5656
def get_test_options(

CONTRIBUTING.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,17 @@ Note: these tests can only be run from an Evergreen host.
275275
- Run `just setup-tests atlas_connect`.
276276
- Run `just run-tests`.
277277

278+
### mod_wsgi tests
279+
280+
Note: these tests can only be run from an Evergreen Linux host that has the Python toolchain.
281+
282+
- Run `just run-server`.
283+
- Run `just setup-tests mod_wsgi <mode>`.
284+
- Run `just run-tests`.
285+
286+
The `mode` can be `standalone` or `embedded`. For the `replica_set` version of the tests, use
287+
`TOPOLOGY=replica_set just run-server`.
288+
278289
### OCSP tests
279290

280291
- Export the orchestration file, e.g. `export ORCHESTRATION_FILE=rsa-basic-tls-ocsp-disableStapling.json`.

0 commit comments

Comments
 (0)