Skip to content

Commit 11a94f4

Browse files
committed
fix load balancer test
1 parent 85f4f64 commit 11a94f4

File tree

5 files changed

+59
-46
lines changed

5 files changed

+59
-46
lines changed

.evergreen/run-tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ if [ -f "./secrets-export.sh" ]; then
2929
. "./secrets-export.sh"
3030
fi
3131

32-
# List the packages
32+
# List the packages.
3333
PIP_QUIET=0 uv run ${UV_ARGS} --with pip pip list
3434

3535
# Start the test runner.

.evergreen/scripts/run_tests.py

Lines changed: 53 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,29 @@
2323
LOGGER = logging.getLogger(__name__)
2424
logging.basicConfig(level=logging.INFO, format="%(levelname)-8s %(message)s")
2525

26-
# Handle green frameworks first so they can patch modules.
27-
if GREEN_FRAMEWORK:
26+
27+
def handle_perf(start_time: datetime, end_time: datetime):
28+
elapsed_secs = (end_time - start_time).total_seconds()
29+
with open("results.json") as fid:
30+
results = json.load(fid)
31+
LOGGER.info("results.json:\n%s", json.dumps(results, indent=2))
32+
33+
results = dict(
34+
status="pass",
35+
exit_code=0,
36+
test_file="BenchMarkTests",
37+
start=int(start_time.timestamp()),
38+
end=int(end_time.timestamp()),
39+
elapsed=elapsed_secs,
40+
)
41+
report = dict(failures=0, results=results)
42+
LOGGER.info("report.json\n%s", json.dumps(report, indent=2))
43+
44+
with open("report.json", "w", newline="\n") as fid:
45+
json.dump(report, fid)
46+
47+
48+
def handle_green_framework() -> None:
2849
if GREEN_FRAMEWORK == "eventlet":
2950
import eventlet
3051

@@ -46,52 +67,44 @@
4667

4768
LOGGER.info(f"Running tests with {GREEN_FRAMEWORK}...")
4869

49-
# Ensure C extensions if applicable.
50-
if not os.environ.get("NO_EXT") and platform.python_implementation() == "CPython":
51-
sys.path.insert(0, str(ROOT / "tools"))
52-
from fail_if_no_c import main as fail_if_no_c
5370

54-
fail_if_no_c()
71+
def run() -> None:
72+
# Handle green frameworks first so they can patch modules.
73+
if GREEN_FRAMEWORK:
74+
handle_green_framework()
5575

56-
if os.environ.get("PYMONGOCRYPT_LIB"):
57-
# Ensure pymongocrypt is working properly.
58-
import pymongocrypt
76+
# Ensure C extensions if applicable.
77+
if not os.environ.get("NO_EXT") and platform.python_implementation() == "CPython":
78+
sys.path.insert(0, str(ROOT / "tools"))
79+
from fail_if_no_c import main as fail_if_no_c
5980

60-
LOGGER.info(f"pymongocrypt version: {pymongocrypt.__version__})")
61-
LOGGER.info(f"libmongocrypt version: {pymongocrypt.libmongocrypt_version()})")
81+
fail_if_no_c()
6282

63-
LOGGER.info(f"Test setup:\n{AUTH=}\n{SSL=}\n{UV_ARGS=}\n{TEST_ARGS=}")
83+
if os.environ.get("PYMONGOCRYPT_LIB"):
84+
# Ensure pymongocrypt is working properly.
85+
import pymongocrypt
6486

65-
# Record the start time for a perf test.
66-
if TEST_PERF:
67-
start_time = datetime.now()
87+
LOGGER.info(f"pymongocrypt version: {pymongocrypt.__version__})")
88+
LOGGER.info(f"libmongocrypt version: {pymongocrypt.libmongocrypt_version()})")
6889

69-
# Run the tests.
70-
pytest.main(TEST_ARGS)
90+
LOGGER.info(f"Test setup:\n{AUTH=}\n{SSL=}\n{UV_ARGS=}\n{TEST_ARGS=}")
7191

72-
# Handle perf test post actions.
73-
if TEST_PERF:
74-
end_time = datetime.now()
75-
elapsed_secs = (end_time - start_time).total_seconds()
76-
with open("results.json") as fid:
77-
results = json.load(fid)
78-
LOGGER.info("results.json:\n%s", json.dumps(results, indent=2))
92+
# Record the start time for a perf test.
93+
if TEST_PERF:
94+
start_time = datetime.now()
7995

80-
results = dict(
81-
status="pass",
82-
exit_code=0,
83-
test_file="BenchMarkTests",
84-
start=int(start_time.timestamp()),
85-
end=int(end_time.timestamp()),
86-
elapsed=elapsed_secs,
87-
)
88-
report = dict(failures=0, results=results)
89-
LOGGER.info("report.json\n%s", json.dumps(report, indent=2))
96+
# Run the tests.
97+
pytest.main(TEST_ARGS)
9098

91-
with open("report.json", "w", newline="\n") as fid:
92-
json.dump(report, fid)
99+
# Handle perf test post actions.
100+
if TEST_PERF:
101+
end_time = datetime.now()
102+
handle_perf(start_time, end_time)
103+
104+
# Handle coverage post actions.
105+
if os.environ.get("COVERAGE"):
106+
shutil.rmtree(".pytest_cache", ignore_errors=True)
93107

94108

95-
# Handle coverage post actions.
96-
if os.environ.get("COVERAGE"):
97-
shutil.rmtree(".pytest_cache", ignore_errors=True)
109+
if __name__ == "__main__":
110+
run()

.evergreen/scripts/setup_tests.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,9 @@ def handle_test_env() -> None:
228228

229229
write_env("AUTH", AUTH)
230230
write_env("SSL", SSL)
231-
write_env("PIP_QUIET") # Quiet by default
232-
write_env("PIP_PREFER_BINARY") # Prefer binary dists by default
233-
write_env("UV_FROZEN") # Do not modify lock files
231+
write_env("PIP_QUIET") # Quiet by default.
232+
write_env("PIP_PREFER_BINARY") # Prefer binary dists by default.
233+
write_env("UV_FROZEN") # Do not modify lock files.
234234

235235
# Skip CSOT tests on non-linux platforms.
236236
if PLATFORM != "linux":

test/asynchronous/helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181

8282
COMPRESSORS = os.environ.get("COMPRESSORS")
8383
MONGODB_API_VERSION = os.environ.get("MONGODB_API_VERSION")
84-
TEST_LOADBALANCER = bool(os.environ.get("TEST_LOADBALANCER"))
84+
TEST_LOADBALANCER = bool(os.environ.get("TEST_LOAD_BALANCER"))
8585
TEST_SERVERLESS = bool(os.environ.get("TEST_SERVERLESS"))
8686
SINGLE_MONGOS_LB_URI = os.environ.get("SINGLE_MONGOS_LB_URI")
8787
MULTI_MONGOS_LB_URI = os.environ.get("MULTI_MONGOS_LB_URI")

test/helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181

8282
COMPRESSORS = os.environ.get("COMPRESSORS")
8383
MONGODB_API_VERSION = os.environ.get("MONGODB_API_VERSION")
84-
TEST_LOADBALANCER = bool(os.environ.get("TEST_LOADBALANCER"))
84+
TEST_LOADBALANCER = bool(os.environ.get("TEST_LOAD_BALANCER"))
8585
TEST_SERVERLESS = bool(os.environ.get("TEST_SERVERLESS"))
8686
SINGLE_MONGOS_LB_URI = os.environ.get("SINGLE_MONGOS_LB_URI")
8787
MULTI_MONGOS_LB_URI = os.environ.get("MULTI_MONGOS_LB_URI")

0 commit comments

Comments
 (0)