Skip to content

Commit 2692d43

Browse files
authored
RUST-1330 Consolidate test script core functions (mongodb#895)
1 parent 79fa2e1 commit 2692d43

25 files changed

+158
-146
lines changed

.evergreen/cargo-test.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/bash
2+
3+
CARGO_OPTIONS=()
4+
TEST_OPTIONS=("-Z unstable-options" "--format json" "--report-time")
5+
FEATURE_FLAGS=()
6+
CARGO_RESULT=0
7+
8+
use_async_runtime() {
9+
if [ "${ASYNC_RUNTIME}" = "async-std" ]; then
10+
FEATURE_FLAGS+=("async-std-runtime")
11+
CARGO_OPTIONS+=("--no-default-features")
12+
elif [ "${ASYNC_RUNTIME}" != "tokio" ]; then
13+
echo "invalid async runtime: ${ASYNC_RUNTIME}" >&2
14+
exit 1
15+
fi
16+
}
17+
18+
join_by() { local IFS="$1"; shift; echo "$*"; }
19+
20+
cargo_test_options() {
21+
local FILTERED=()
22+
for FEAT in "${FEATURE_FLAGS[@]}"; do
23+
[[ "${FEAT}" != "" ]] && FILTERED+=("${FEAT}")
24+
done
25+
local FEATURE_OPTION=""
26+
if (( ${#FILTERED[@]} != 0 )); then
27+
FEATURE_OPTION="--features $(join_by , "${FILTERED[@]}")"
28+
fi
29+
local THREAD_OPTION=""
30+
if [ "${SINGLE_THREAD}" = true ]; then
31+
THREAD_OPTION="--test-threads=1"
32+
fi
33+
echo $1 ${CARGO_OPTIONS[@]} ${FEATURE_OPTION} -- ${TEST_OPTIONS[@]} ${THREAD_OPTION}
34+
}
35+
36+
cargo_test() {
37+
RUST_BACKTRACE=1 \
38+
cargo test $(cargo_test_options $1) \
39+
| grep -v '{"t":' \
40+
| cargo2junit
41+
(( CARGO_RESULT = ${CARGO_RESULT} || $? ))
42+
}

.evergreen/check-cargo-deny.sh

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

33
set -o errexit
44

5-
source ./.evergreen/configure-rust.sh
5+
source ./.evergreen/env.sh
66

77
cargo install --locked cargo-deny
88
cargo deny --all-features check

.evergreen/check-clippy.sh

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

33
set -o errexit
44

5-
source ./.evergreen/configure-rust.sh
5+
source ./.evergreen/env.sh
66
source ./.evergreen/feature-combinations.sh
77

88
# Pin clippy to the latest version. This should be updated when new versions of Rust are released.

.evergreen/check-rustdoc.sh

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

33
set -o errexit
44

5-
source ./.evergreen/configure-rust.sh
5+
source ./.evergreen/env.sh
66

77
# docs.rs builds the driver on a read-only file system. to create a more realistic environment, we first
88
# build the driver to ensure we have all the deps already in src, and then limit the permissions on that directory

.evergreen/check-rustfmt.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
set -o errexit
44

5-
source ./.evergreen/configure-rust.sh
5+
source ./.evergreen/env.sh
66
rustfmt +nightly --unstable-features --check src/**/*.rs
77
rustfmt +nightly --unstable-features --check src/*.rs

.evergreen/compile-only.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
set -o errexit
44
set -o xtrace
55

6-
source ./.evergreen/configure-rust.sh
6+
source ./.evergreen/env.sh
77
rustup update $RUST_VERSION
88

99
# pin dependencies who have bumped their MSRVs to > ours in recent releases.

.evergreen/config.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ functions:
287287
288288
# compile mini test project
289289
cd $PROJECT_DIRECTORY/.evergreen/aws-ecs-test
290-
. ${PROJECT_DIRECTORY}/.evergreen/configure-rust.sh
290+
. ${PROJECT_DIRECTORY}/.evergreen/env.sh
291291
cargo build
292292
cd -
293293
@@ -619,7 +619,7 @@ functions:
619619
cp -r $MONGOCRYPT_LIB_DIR test-contents
620620
621621
echo "Building test ... begin"
622-
. ${PROJECT_DIRECTORY}/.evergreen/configure-rust.sh
622+
. ${PROJECT_DIRECTORY}/.evergreen/env.sh
623623
cargo test get_exe_name --features in-use-encryption-unstable,gcp-kms -- --ignored
624624
cp $(cat exe_name.txt) test-contents/test-exe
625625
echo "Building test ... end"
@@ -1007,6 +1007,7 @@ tasks:
10071007
# "4.4" explicitly left off to keep this out of the generic matrix
10081008
tags: ["aws-auth"]
10091009
commands:
1010+
- func: "install junit dependencies"
10101011
- func: "bootstrap mongo-orchestration"
10111012
vars:
10121013
ORCHESTRATION_FILE: "auth-aws.json"
@@ -1068,6 +1069,7 @@ tasks:
10681069
# "5.0" explicitly left off to keep this out of the generic matrix
10691070
tags: ["aws-auth"]
10701071
commands:
1072+
- func: "install junit dependencies"
10711073
- func: "bootstrap mongo-orchestration"
10721074
vars:
10731075
ORCHESTRATION_FILE: "auth-aws.json"
@@ -1129,6 +1131,7 @@ tasks:
11291131
# "6.0" explicitly left off to keep this out of the generic matrix
11301132
tags: ["aws-auth"]
11311133
commands:
1134+
- func: "install junit dependencies"
11321135
- func: "bootstrap mongo-orchestration"
11331136
vars:
11341137
ORCHESTRATION_FILE: "auth-aws.json"
@@ -1190,6 +1193,7 @@ tasks:
11901193
# "7.0" explicitly left off to keep this out of the generic matrix
11911194
tags: ["aws-auth"]
11921195
commands:
1196+
- func: "install junit dependencies"
11931197
- func: "bootstrap mongo-orchestration"
11941198
vars:
11951199
ORCHESTRATION_FILE: "auth-aws.json"
@@ -1251,6 +1255,7 @@ tasks:
12511255
# "rapid" explicitly left off to keep this out of the generic matrix
12521256
tags: ["aws-auth"]
12531257
commands:
1258+
- func: "install junit dependencies"
12541259
- func: "bootstrap mongo-orchestration"
12551260
vars:
12561261
ORCHESTRATION_FILE: "auth-aws.json"
@@ -1313,6 +1318,7 @@ tasks:
13131318
# "latest" explicitly left off to keep this out of the generic matrix
13141319
tags: ["aws-auth"]
13151320
commands:
1321+
- func: "install junit dependencies"
13161322
- func: "bootstrap mongo-orchestration"
13171323
vars:
13181324
ORCHESTRATION_FILE: "auth-aws.json"
@@ -1330,6 +1336,7 @@ tasks:
13301336

13311337
- name: "test-connection-string"
13321338
commands:
1339+
- func: "install junit dependencies"
13331340
- func: "run connection string tests"
13341341

13351342
- name: "test-serverless"
@@ -1377,6 +1384,7 @@ tasks:
13771384
- name: "test-atlas-connectivity"
13781385
tags: ["atlas-connect"]
13791386
commands:
1387+
- func: "install junit dependencies"
13801388
- func: "run atlas tests"
13811389

13821390
- name: "test-x509-auth"
@@ -1390,6 +1398,7 @@ tasks:
13901398

13911399
- name: "test-plain-auth"
13921400
commands:
1401+
- func: "install junit dependencies"
13931402
- func: "run plain tests"
13941403

13951404
- name: "test-gcp-kms"

.evergreen/configure-rust.sh

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

.evergreen/env.sh

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
11
#!/bin/bash
22

3-
source ./.evergreen/configure-rust.sh
4-
3+
export RUSTUP_HOME="${PROJECT_DIRECTORY}/.rustup"
4+
export PATH="${RUSTUP_HOME}/bin:$PATH"
5+
export CARGO_HOME="${PROJECT_DIRECTORY}/.cargo"
6+
export PATH="${CARGO_HOME}/bin:$PATH"
57
NODE_ARTIFACTS_PATH="${PROJECT_DIRECTORY}/node-artifacts"
68
export NVM_DIR="${NODE_ARTIFACTS_PATH}/nvm"
79

10+
. ${CARGO_HOME}/env
11+
812
if [[ "$OS" == "Windows_NT" ]]; then
13+
# Update path for DLLs
14+
export PATH="${MONGOCRYPT_LIB_DIR}/../bin:$PATH"
15+
16+
# rustup/cargo need the native Windows paths; $PROJECT_DIRECTORY is a cygwin path
17+
export RUSTUP_HOME=$(cygpath ${RUSTUP_HOME} --windows)
18+
export CARGO_HOME=$(cygpath ${CARGO_HOME} --windows)
19+
export MONGOCRYPT_LIB_DIR=$(cygpath ${MONGOCRYPT_LIB_DIR} --windows)
20+
921
NVM_HOME=$(cygpath -w "$NVM_DIR")
1022
export NVM_HOME
1123
NVM_SYMLINK=$(cygpath -w "$NODE_ARTIFACTS_PATH/bin")
@@ -14,7 +26,6 @@ if [[ "$OS" == "Windows_NT" ]]; then
1426
export NVM_ARTIFACTS_PATH
1527
export OPENSSL_DIR="C:\\openssl"
1628
OPENSSL_LIB_PATH=$(cygpath $OPENSSL_DIR/lib)
17-
ls $OPENSSL_LIB_PATH
1829
PATH=$(cygpath $NVM_SYMLINK):$(cygpath $NVM_HOME):$PATH
1930
export PATH
2031
echo "updated path on windows PATH=$PATH"

.evergreen/install-dependencies.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ for arg; do
2525
echo 'export PATH="$PATH:${CARGO_HOME}/bin"' >> ${CARGO_HOME}/env
2626
echo "export CARGO_NET_GIT_FETCH_WITH_CLI=true" >> ${CARGO_HOME}/env
2727

28-
source .evergreen/configure-rust.sh
28+
source .evergreen/env.sh
2929
rustup toolchain install nightly -c rustfmt
3030
# TODO RUST-1674: remove this workaround
3131
rustup default 1.69

.evergreen/release-danger-do-not-run-manually.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ fi
2626
git fetch origin tag $TAG --no-tags
2727
git checkout $TAG
2828

29-
source ./.evergreen/configure-rust.sh
29+
source ./.evergreen/env.sh
3030

3131
cargo publish --token $TOKEN

.evergreen/run-atlas-tests.sh

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
#!/bin/bash
22

33
set -o errexit
4+
set -o pipefail
45

5-
if [ "$ASYNC_RUNTIME" = "tokio" ]; then
6-
OPTIONS=""
7-
elif [ "$ASYNC_RUNTIME" = "async-std" ]; then
8-
OPTIONS=" --no-default-features --features async-std-runtime"
9-
else
10-
echo "invalid async runtime: ${ASYNC_RUNTIME}" >&2
11-
exit 1
12-
fi
13-
14-
source ./.evergreen/configure-rust.sh
15-
RUST_BACKTRACE=1 cargo test atlas_connectivity ${OPTIONS}
6+
source .evergreen/env.sh
7+
source .evergreen/cargo-test.sh
8+
9+
use_async_runtime
10+
11+
set +o errexit
12+
13+
cargo_test atlas_connectivity > results.xml
14+
15+
exit $CARGO_RESULT

.evergreen/run-aws-tests.sh

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,16 @@ set -x
4242

4343
set -o errexit
4444

45-
source ./.evergreen/configure-rust.sh
45+
source .evergreen/env.sh
46+
source .evergreen/cargo-test.sh
4647

47-
RUST_BACKTRACE=1 cargo test --features aws-auth auth_aws
48-
RUST_BACKTRACE=1 cargo test --features aws-auth lambda_examples::auth::test_handler
48+
FEATURE_FLAGS+=("aws-auth")
49+
50+
set +o errexit
51+
52+
cargo_test auth_aws > auth_aws.xml
53+
cargo_test lambda_examples::auth::test_handler > lambda_handler.xml
54+
55+
junit-report-merger results.xml auth_aws.xml lambda_handler.xml
56+
57+
exit $CARGO_RESULT

.evergreen/run-azure-kms-test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
set -o errexit
44
set -o pipefail
55

6-
source ./.evergreen/configure-rust.sh
6+
source ./.evergreen/env.sh
77

88
set -o xtrace
99

.evergreen/run-bson-benchmarks.sh

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

33
set -o errexit
44

5-
source ./.evergreen/configure-rust.sh
5+
source ./.evergreen/env.sh
66

77
cd benchmarks
88
cargo run \

.evergreen/run-compile-benchmarks.sh

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

33
set -o errexit
44

5-
source ./.evergreen/configure-rust.sh
5+
source ./.evergreen/env.sh
66

77
FEATURES=""
88

.evergreen/run-connection-string-tests.sh

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,19 @@
22

33
set -o errexit
44
set -o xtrace
5+
set -o pipefail
56

6-
source ./.evergreen/configure-rust.sh
7+
source .evergreen/env.sh
8+
source .evergreen/cargo-test.sh
79

8-
RUST_BACKTRACE=1 cargo test --features aws-auth spec::auth
9-
RUST_BACKTRACE=1 cargo test --features aws-auth uri_options
10-
RUST_BACKTRACE=1 cargo test --features aws-auth connection_string
10+
FEATURE_FLAGS+=("aws-auth")
11+
12+
set +o errexit
13+
14+
cargo_test spec::auth > spec.xml
15+
cargo_test uri_options > uri_options.xml
16+
cargo_test connection_string > connection_string.xml
17+
18+
junit-report-merger results.xml spec.xml uri_options.xml connection_string.xml
19+
20+
exit ${CARGO_RESULT}

.evergreen/run-csfle-tests.sh

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,11 @@ set -o errexit
44
set -o pipefail
55

66
source ./.evergreen/env.sh
7+
source .evergreen/cargo-test.sh
78

89
set -o xtrace
910

10-
FEATURE_FLAGS="in-use-encryption-unstable,aws-auth,azure-kms,${TLS_FEATURE}"
11-
OPTIONS="-- -Z unstable-options --format json --report-time"
12-
13-
if [ "$SINGLE_THREAD" = true ]; then
14-
OPTIONS="$OPTIONS --test-threads=1"
15-
fi
11+
FEATURE_FLAGS+=("in-use-encryption-unstable" "aws-auth" "azure-kms" "${TLS_FEATURE}")
1612

1713
if [ "$OS" = "Windows_NT" ]; then
1814
export CSFLE_TLS_CERT_DIR=$(cygpath ${CSFLE_TLS_CERT_DIR} --windows)
@@ -23,15 +19,7 @@ fi
2319
export AWS_DEFAULT_REGION=us-east-1
2420
. ${DRIVERS_TOOLS}/.evergreen/csfle/set-temp-creds.sh
2521

26-
echo "cargo test options: --features ${FEATURE_FLAGS} ${OPTIONS}"
27-
28-
CARGO_RESULT=0
29-
30-
cargo_test() {
31-
RUST_BACKTRACE=1 \
32-
cargo test --features ${FEATURE_FLAGS} $1 ${OPTIONS} | grep -v '{"t":' | cargo2junit
33-
(( CARGO_RESULT = ${CARGO_RESULT} || $? ))
34-
}
22+
echo "cargo test options: $(cargo_test_options)"
3523

3624
set +o errexit
3725

.evergreen/run-driver-benchmarks.sh

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

33
set -o errexit
44

5-
source ./.evergreen/configure-rust.sh
5+
source ./.evergreen/env.sh
66

77
FEATURES=""
88

0 commit comments

Comments
 (0)