Skip to content

Commit 34d3494

Browse files
committed
Fix evg tests
1 parent 9e62c13 commit 34d3494

6 files changed

Lines changed: 64 additions & 28 deletions

File tree

.evergreen/generated_configs/functions.yml

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -258,23 +258,8 @@ functions:
258258
params:
259259
binary: bash
260260
args:
261-
- .evergreen/just.sh
262-
- setup-tests
263-
- ${TEST_NAME}
264-
- ""
265-
working_dir: src
266-
include_expansions_in_env:
267-
- TOOLCHAIN_VERSION
268-
- PYMONGO_BUILD_RUST
269-
- PYMONGO_USE_RUST
270-
- TEST_ARGS
271-
type: test
272-
- command: subprocess.exec
273-
params:
274-
binary: bash
275-
args:
276-
- .evergreen/just.sh
277-
- run-tests
261+
- -c
262+
- "if [ -f .evergreen/scripts/env.sh ]; then . .evergreen/scripts/env.sh; fi; if [ \"Windows_NT\" = \"${OS:-}\" ]; then CARGO_BIN=\"$USERPROFILE/.cargo/bin\"; else CARGO_BIN=\"$HOME/.cargo/bin\"; fi; if ! command -v cargo &> /dev/null; then echo \"Installing Rust...\"; curl --proto \"=https\" --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y; fi; export PATH=\"$CARGO_BIN:$PATH\"; echo \"Rust toolchain: $(rustc --version 2>/dev/null || echo not found)\"; echo \"Cargo: $(cargo --version 2>/dev/null || echo not found)\"; echo \"Cargo path: $(command -v cargo || echo not found)\"; if [ -f .evergreen/scripts/env.sh ]; then echo \"export PATH=\\\"$CARGO_BIN:\\$PATH\\\"\" >> .evergreen/scripts/env.sh; fi; bash .evergreen/just.sh setup-tests \"${TEST_NAME}\" \"\"; bash .evergreen/just.sh run-tests"
278263
working_dir: src
279264
include_expansions_in_env:
280265
- TOOLCHAIN_VERSION

.evergreen/generated_configs/tasks.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5031,23 +5031,23 @@ tasks:
50315031
# Test rust tests
50325032
- name: test-rust-python3.10
50335033
commands:
5034-
- func: run tests
5034+
- func: run rust tests
50355035
vars:
50365036
TOOLCHAIN_VERSION: "3.10"
50375037
TEST_NAME: test_bson
50385038
TEST_ARGS: test/test_bson.py -v
50395039
tags: [test-rust, python-3.10]
50405040
- name: test-rust-python3.12
50415041
commands:
5042-
- func: run tests
5042+
- func: run rust tests
50435043
vars:
50445044
TOOLCHAIN_VERSION: "3.12"
50455045
TEST_NAME: test_bson
50465046
TEST_ARGS: test/test_bson.py -v
50475047
tags: [test-rust, python-3.12]
50485048
- name: test-rust-python3.14
50495049
commands:
5050-
- func: run tests
5050+
- func: run rust tests
50515051
vars:
50525052
TOOLCHAIN_VERSION: "3.14"
50535053
TEST_NAME: test_bson

.evergreen/scripts/generate_config.py

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,7 +1273,7 @@ def create_test_rust_tasks():
12731273
tags.append("pr") # Run on PRs for latest Python
12741274
task_name = get_task_name("test-rust", python=python)
12751275
test_func = FunctionCall(
1276-
func="run tests",
1276+
func="run rust tests",
12771277
vars=dict(
12781278
TOOLCHAIN_VERSION=python,
12791279
TEST_NAME="test_bson",
@@ -1305,14 +1305,53 @@ def create_test_rust_variants() -> list[BuildVariant]:
13051305

13061306

13071307
def create_test_rust_func():
1308-
"""Create function for running Rust extension tests."""
1308+
"""Create function for running Rust extension tests.
1309+
1310+
This function installs Rust if needed, then runs the test setup and execution.
1311+
The Rust installation and PATH setup happens in a single shell session to ensure
1312+
cargo is available for the package build.
1313+
"""
13091314
includes = ["TOOLCHAIN_VERSION", "PYMONGO_BUILD_RUST", "PYMONGO_USE_RUST", "TEST_ARGS"]
1310-
args = [".evergreen/just.sh", "setup-tests", "${TEST_NAME}", ""]
1311-
setup_cmd = get_subprocess_exec(include_expansions_in_env=includes, args=args)
1312-
test_cmd = get_subprocess_exec(
1313-
include_expansions_in_env=includes, args=[".evergreen/just.sh", "run-tests"]
1315+
1316+
# Run everything in a single shell session to ensure Rust is available
1317+
# This combines: Rust installation + setup-tests + run-tests
1318+
# Note: get_subprocess_exec defaults to binary="bash", so we only need args
1319+
combined_cmd = get_subprocess_exec(
1320+
include_expansions_in_env=includes,
1321+
args=[
1322+
"-c",
1323+
# Source env.sh first to get the base PATH
1324+
"if [ -f .evergreen/scripts/env.sh ]; then "
1325+
". .evergreen/scripts/env.sh; "
1326+
"fi; "
1327+
# Determine cargo path based on OS
1328+
'if [ "Windows_NT" = "${OS:-}" ]; then '
1329+
'CARGO_BIN="$USERPROFILE/.cargo/bin"; '
1330+
"else "
1331+
'CARGO_BIN="$HOME/.cargo/bin"; '
1332+
"fi; "
1333+
# Install Rust if needed
1334+
"if ! command -v cargo &> /dev/null; then "
1335+
'echo "Installing Rust..."; '
1336+
'curl --proto "=https" --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y; '
1337+
"fi; "
1338+
# Ensure cargo is in PATH for all subsequent commands
1339+
'export PATH="$CARGO_BIN:$PATH"; '
1340+
'echo "Rust toolchain: $(rustc --version 2>/dev/null || echo not found)"; '
1341+
'echo "Cargo: $(cargo --version 2>/dev/null || echo not found)"; '
1342+
'echo "Cargo path: $(command -v cargo || echo not found)"; '
1343+
# Update env.sh to include cargo in PATH for subsequent shell sessions
1344+
"if [ -f .evergreen/scripts/env.sh ]; then "
1345+
'echo "export PATH=\\"$CARGO_BIN:\\$PATH\\"" >> .evergreen/scripts/env.sh; '
1346+
"fi; "
1347+
# Run setup-tests
1348+
'bash .evergreen/just.sh setup-tests "${TEST_NAME}" ""; '
1349+
# Run tests
1350+
"bash .evergreen/just.sh run-tests",
1351+
],
13141352
)
1315-
return "run rust tests", [setup_cmd, test_cmd]
1353+
1354+
return "run rust tests", [combined_cmd]
13161355

13171356

13181357
mod = sys.modules[__name__]

.evergreen/scripts/install-dependencies.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ fi
3030

3131
# Ensure just is installed.
3232
if ! command -v just &>/dev/null; then
33-
uv tool install rust-just
33+
uv tool install rust-just || uv tool install --force rust-just
3434
fi
3535

3636
popd > /dev/null

.evergreen/scripts/run_tests.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,16 @@ def run() -> None:
151151
if os.environ.get("PYMONGOCRYPT_LIB"):
152152
handle_pymongocrypt()
153153

154+
# Check if Rust extension is being used
155+
if os.environ.get("PYMONGO_USE_RUST") or os.environ.get("PYMONGO_BUILD_RUST"):
156+
try:
157+
import bson
158+
159+
LOGGER.info(f"BSON implementation: {bson.get_bson_implementation()}")
160+
LOGGER.info(f"Has Rust: {bson.has_rust()}, Has C: {bson.has_c()}")
161+
except Exception as e:
162+
LOGGER.warning(f"Could not check BSON implementation: {e}")
163+
154164
LOGGER.info(f"Test setup:\n{AUTH=}\n{SSL=}\n{UV_ARGS=}\n{TEST_ARGS=}")
155165

156166
# Record the start time for a perf test.

.evergreen/scripts/setup_tests.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
"UV_PYTHON",
3333
"REQUIRE_FIPS",
3434
"IS_WIN32",
35+
"PYMONGO_USE_RUST",
36+
"PYMONGO_BUILD_RUST",
3537
]
3638

3739
# Map the test name to test extra.

0 commit comments

Comments
 (0)