Skip to content

Commit c6bceb3

Browse files
committed
Merge branch 'master' of github.com:mongodb/mongo-python-driver into PYTHON-5213
2 parents 2a1affe + 4353278 commit c6bceb3

File tree

12 files changed

+199
-119
lines changed

12 files changed

+199
-119
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
@@ -356,40 +345,6 @@ tasks:
356345
- func: "run server"
357346
- func: "run doctests"
358347

359-
- name: "mod-wsgi-standalone"
360-
tags: ["mod_wsgi"]
361-
commands:
362-
- func: "run server"
363-
vars:
364-
TOPOLOGY: "server"
365-
- func: "run mod_wsgi tests"
366-
367-
- name: "mod-wsgi-replica-set"
368-
tags: ["mod_wsgi"]
369-
commands:
370-
- func: "run server"
371-
vars:
372-
TOPOLOGY: "replica_set"
373-
- func: "run mod_wsgi tests"
374-
375-
- name: "mod-wsgi-embedded-mode-standalone"
376-
tags: ["mod_wsgi"]
377-
commands:
378-
- func: "run server"
379-
- func: "run mod_wsgi tests"
380-
vars:
381-
MOD_WSGI_EMBEDDED: "1"
382-
383-
- name: "mod-wsgi-embedded-mode-replica-set"
384-
tags: ["mod_wsgi"]
385-
commands:
386-
- func: "run server"
387-
vars:
388-
TOPOLOGY: "replica_set"
389-
- func: "run mod_wsgi tests"
390-
vars:
391-
MOD_WSGI_EMBEDDED: "1"
392-
393348
- name: "no-server"
394349
tags: ["no-server"]
395350
commands:

.evergreen/generated_configs/tasks.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,48 @@ tasks:
787787
TEST_NAME: load_balancer
788788
tags: [load-balancer, noauth, nossl]
789789

790+
# Mod wsgi tests
791+
- name: mod-wsgi-standalone
792+
commands:
793+
- func: run server
794+
vars:
795+
TOPOLOGY: standalone
796+
- func: run tests
797+
vars:
798+
TEST_NAME: mod_wsgi
799+
SUB_TEST_NAME: standalone
800+
tags: [mod_wsgi]
801+
- name: mod-wsgi-replica-set
802+
commands:
803+
- func: run server
804+
vars:
805+
TOPOLOGY: replica_set
806+
- func: run tests
807+
vars:
808+
TEST_NAME: mod_wsgi
809+
SUB_TEST_NAME: standalone
810+
tags: [mod_wsgi]
811+
- name: mod-wsgi-embedded-mode-standalone
812+
commands:
813+
- func: run server
814+
vars:
815+
TOPOLOGY: standalone
816+
- func: run tests
817+
vars:
818+
TEST_NAME: mod_wsgi
819+
SUB_TEST_NAME: embedded
820+
tags: [mod_wsgi]
821+
- name: mod-wsgi-embedded-mode-replica-set
822+
commands:
823+
- func: run server
824+
vars:
825+
TOPOLOGY: replica_set
826+
- func: run tests
827+
vars:
828+
TEST_NAME: mod_wsgi
829+
SUB_TEST_NAME: embedded
830+
tags: [mod_wsgi]
831+
790832
# Ocsp tests
791833
- name: test-ocsp-ecdsa-valid-cert-server-does-not-staple
792834
commands:

.evergreen/generated_configs/variants.yml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -704,10 +704,7 @@ buildvariants:
704704
# Mod wsgi tests
705705
- name: mod_wsgi-ubuntu-22-python3.9
706706
tasks:
707-
- name: mod-wsgi-standalone
708-
- name: mod-wsgi-replica-set
709-
- name: mod-wsgi-embedded-mode-standalone
710-
- name: mod-wsgi-embedded-mode-replica-set
707+
- name: .mod_wsgi
711708
display_name: mod_wsgi Ubuntu-22 Python3.9
712709
run_on:
713710
- ubuntu2204-small
@@ -716,10 +713,7 @@ buildvariants:
716713
PYTHON_BINARY: /opt/python/3.9/bin/python3
717714
- name: mod_wsgi-ubuntu-22-python3.13
718715
tasks:
719-
- name: mod-wsgi-standalone
720-
- name: mod-wsgi-replica-set
721-
- name: mod-wsgi-embedded-mode-standalone
722-
- name: mod-wsgi-embedded-mode-replica-set
716+
- name: .mod_wsgi
723717
display_name: mod_wsgi Ubuntu-22 Python3.13
724718
run_on:
725719
- ubuntu2204-small

.evergreen/scripts/generate_config.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -614,12 +614,7 @@ def create_atlas_data_lake_variants():
614614
def create_mod_wsgi_variants():
615615
variants = []
616616
host = HOSTS["ubuntu22"]
617-
tasks = [
618-
"mod-wsgi-standalone",
619-
"mod-wsgi-replica-set",
620-
"mod-wsgi-embedded-mode-standalone",
621-
"mod-wsgi-embedded-mode-replica-set",
622-
]
617+
tasks = [".mod_wsgi"]
623618
expansions = dict(MOD_WSGI_VERSION="4")
624619
for python in MIN_MAX_PYTHON:
625620
display_name = get_display_name("mod_wsgi", host, python=python)
@@ -897,6 +892,24 @@ def create_oidc_tasks():
897892
return tasks
898893

899894

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.replace("_", "-")
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.split("-")[0])
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+
900913
def _create_ocsp_task(algo, variant, server_type, base_task_name):
901914
file_name = f"{algo}-basic-tls-ocsp-{variant}.json"
902915

.evergreen/scripts/mod_wsgi_tester.py

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
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+
write_env("MOD_WSGI_CONF", env["MOD_WSGI_CONF"])
34+
apache = which("apache2")
35+
if not apache and Path("/usr/lib/apache2/mpm-prefork/apache2").exists():
36+
apache = "/usr/lib/apache2/mpm-prefork/apache2"
37+
if apache:
38+
apache_config = "apache24ubuntu161404.conf"
39+
else:
40+
apache = which("httpd")
41+
if not apache:
42+
raise ValueError("Could not find apache2 or httpd")
43+
apache_config = "apache22amazon.conf"
44+
python_version = ".".join(str(val) for val in sys.version_info[:2])
45+
mod_wsgi_version = 4
46+
so_file = f"/opt/python/mod_wsgi/python_version/{python_version}/mod_wsgi_version/{mod_wsgi_version}/mod_wsgi.so"
47+
write_env("MOD_WSGI_SO", so_file)
48+
env["MOD_WSGI_SO"] = so_file
49+
env["PYTHONHOME"] = f"/opt/python/{python_version}"
50+
env["PROJECT_DIRECTORY"] = project_directory = str(ROOT)
51+
write_env("APACHE_BINARY", apache)
52+
write_env("APACHE_CONFIG", apache_config)
53+
uri1 = f"http://localhost:8080/interpreter1{project_directory}"
54+
write_env("TEST_URI1", uri1)
55+
uri2 = f"http://localhost:8080/interpreter2{project_directory}"
56+
write_env("TEST_URI2", uri2)
57+
run_command(f"{apache} -k start -f {ROOT}/test/mod_wsgi_test/{apache_config}", env=env)
58+
59+
# Wait for the endpoints to be available.
60+
try:
61+
make_request(uri1, 10)
62+
make_request(uri2, 10)
63+
except Exception as e:
64+
LOGGER.error(Path("error_log").read_text())
65+
raise e
66+
67+
68+
def test_mod_wsgi() -> None:
69+
sys.path.insert(0, ROOT)
70+
from test.mod_wsgi_test.test_client import main, parse_args
71+
72+
uri1 = os.environ["TEST_URI1"]
73+
uri2 = os.environ["TEST_URI2"]
74+
args = f"-n 25000 -t 100 parallel {uri1} {uri2}"
75+
try:
76+
main(*parse_args(args.split()))
77+
78+
args = f"-n 25000 serial {uri1} {uri2}"
79+
main(*parse_args(args.split()))
80+
except Exception as e:
81+
LOGGER.error(Path("error_log").read_text())
82+
raise e
83+
84+
85+
def teardown_mod_wsgi() -> None:
86+
apache = os.environ["APACHE_BINARY"]
87+
apache_config = os.environ["APACHE_CONFIG"]
88+
89+
run_command(f"{apache} -k stop -f {ROOT}/test/mod_wsgi_test/{apache_config}")
90+
91+
92+
if __name__ == "__main__":
93+
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
@@ -138,6 +138,13 @@ def run() -> None:
138138
if TEST_PERF:
139139
start_time = datetime.now()
140140

141+
# Run mod_wsgi tests using the helper.
142+
if TEST_NAME == "mod_wsgi":
143+
from mod_wsgi_tester import test_mod_wsgi
144+
145+
test_mod_wsgi()
146+
return
147+
141148
# Send kms tests to run remotely.
142149
if TEST_NAME == "kms" and SUB_TEST_NAME in ["azure", "gcp"]:
143150
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
@@ -264,6 +264,11 @@ def handle_test_env() -> None:
264264
cmd = f'bash "{DRIVERS_TOOLS}/.evergreen/run-load-balancer.sh" start'
265265
run_command(cmd)
266266

267+
if test_name == "mod_wsgi":
268+
from mod_wsgi_tester import setup_mod_wsgi
269+
270+
setup_mod_wsgi(sub_test_name)
271+
267272
if test_name == "ocsp":
268273
if sub_test_name:
269274
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
@@ -48,4 +48,10 @@
4848
elif TEST_NAME == "auth_aws" and sys.platform != "darwin":
4949
run_command(f"bash {DRIVERS_TOOLS}/.evergreen/auth_aws/teardown.sh")
5050

51+
# Tear down mog_wsgi if applicable.
52+
elif TEST_NAME == "mod_wsgi":
53+
from mod_wsgi_tester import teardown_mod_wsgi
54+
55+
teardown_mod_wsgi()
56+
5157
LOGGER.info(f"Tearing down tests of type '{TEST_NAME}'... done.")

.evergreen/scripts/utils.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ 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"]
54+
55+
EXTRA_TESTS = ["mod_wsgi", "aws_lambda", "index_management"]
5456

5557

5658
def get_test_options(
@@ -62,7 +64,7 @@ def get_test_options(
6264
if require_sub_test_name:
6365
parser.add_argument(
6466
"test_name",
65-
choices=sorted(TEST_SUITE_MAP) + ["aws_lambda", "index_management"], # noqa: RUF005
67+
choices=sorted(list(TEST_SUITE_MAP) + EXTRA_TESTS),
6668
nargs="?",
6769
default="default",
6870
help="The optional name of the test suite to set up, typically the same name as a pytest marker.",
@@ -137,6 +139,11 @@ def run_command(cmd: str | list[str], **kwargs: Any) -> None:
137139
cmd = " ".join(cmd)
138140
LOGGER.info("Running command '%s'...", cmd)
139141
kwargs.setdefault("check", True)
142+
# Prevent overriding the python used by other tools.
143+
env = kwargs.pop("env", os.environ).copy()
144+
if "UV_PYTHON" in env:
145+
del env["UV_PYTHON"]
146+
kwargs["env"] = env
140147
try:
141148
subprocess.run(shlex.split(cmd), **kwargs) # noqa: PLW1510, S603
142149
except subprocess.CalledProcessError as e:

0 commit comments

Comments
 (0)