Skip to content

Commit e6892af

Browse files
authored
RUST-1674 Use cargo-nextest as test runner (mongodb#929)
1 parent e2d0f44 commit e6892af

15 files changed

+58
-51
lines changed

.config/nextest.toml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[profile.default]
2+
retries = 1
3+
4+
[profile.ci]
5+
failure-output = "final"
6+
test-threads = 1
7+
fail-fast = false
8+
9+
[profile.ci.junit]
10+
path = "junit.xml"

.evergreen/cargo-test.sh

+4-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22

33
CARGO_OPTIONS=()
4-
TEST_OPTIONS=("-Z unstable-options" "--format json" "--report-time")
4+
TEST_OPTIONS=()
55
FEATURE_FLAGS=()
66
CARGO_RESULT=0
77

@@ -26,17 +26,11 @@ cargo_test_options() {
2626
if (( ${#FILTERED[@]} != 0 )); then
2727
FEATURE_OPTION="--features $(join_by , "${FILTERED[@]}")"
2828
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}
29+
echo $1 ${CARGO_OPTIONS[@]} ${FEATURE_OPTION} -- ${TEST_OPTIONS[@]}
3430
}
3531

3632
cargo_test() {
37-
RUST_BACKTRACE=1 \
38-
cargo test $(cargo_test_options $1) \
39-
| grep -v '{"t":' \
40-
| cargo2junit
33+
RUST_BACKTRACE=1 cargo nextest run --profile ci $(cargo_test_options $1)
4134
(( CARGO_RESULT = ${CARGO_RESULT} || $? ))
35+
mv target/nextest/ci/junit.xml $2
4236
}

.evergreen/config.yml

+5-8
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ stepback: true
1313
command_type: system
1414

1515
# Protect ourself against rogue test case, or curl gone wild, that runs forever
16-
# 12 minutes is the longest we'll ever run
17-
exec_timeout_secs: 3600 # 12 minutes is the longest we'll ever run
16+
# TODO RUST-1721 Reduce this
17+
exec_timeout_secs: 5400
1818

1919
# What to do when evergreen hits the timeout (`post:` tasks are run automatically)
2020
timeout:
@@ -453,8 +453,7 @@ functions:
453453
SNAPPY_COMPRESSION_ENABLED=${SNAPPY_COMPRESSION_ENABLED} \
454454
ZLIB_COMPRESSION_ENABLED=${ZLIB_COMPRESSION_ENABLED} \
455455
ZSTD_COMPRESSION_ENABLED=${ZSTD_COMPRESSION_ENABLED} \
456-
SINGLE_THREAD=${SINGLE_THREAD} \
457-
ASYNC_RUNTIME=${ASYNC_RUNTIME} \
456+
ASYNC_RUNTIME=${ASYNC_RUNTIME} \
458457
MONGODB_API_VERSION=${MONGODB_API_VERSION} \
459458
TLS_FEATURE=${TLS_FEATURE} \
460459
.evergreen/run-tests.sh
@@ -477,9 +476,8 @@ functions:
477476
. .evergreen/generate-uri.sh
478477
479478
SNAPPY_COMPRESSION_ENABLED="true" \
480-
ZLIB_COMPRESSION_ENABLED="true" \
481-
ZSTD_COMPRESSION_ENABLED="true" \
482-
SINGLE_THREAD=${SINGLE_THREAD} \
479+
ZLIB_COMPRESSION_ENABLED="true" \
480+
ZSTD_COMPRESSION_ENABLED="true" \
483481
ASYNC_RUNTIME=${ASYNC_RUNTIME} \
484482
MONGODB_API_VERSION=${MONGODB_API_VERSION} \
485483
TLS_FEATURE=${TLS_FEATURE} \
@@ -1625,7 +1623,6 @@ axes:
16251623
display_name: "MacOS 11.00"
16261624
run_on: macos-1100
16271625
variables:
1628-
SINGLE_THREAD: true
16291626
VENV_BIN_DIR: "bin"
16301627
LIBMONGOCRYPT_OS: "macos"
16311628
- id: windows-64-vs2017

.evergreen/install-dependencies.sh

+3-4
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,21 @@ for arg; do
2727

2828
source .evergreen/env.sh
2929
rustup toolchain install nightly -c rustfmt
30-
# TODO RUST-1674: remove this workaround
31-
rustup default 1.69
3230
elif [ $arg == "mdbook" ]; then
3331
source ${CARGO_HOME}/env
3432
# Install the manual rendering tool
3533
cargo install mdbook
3634
elif [ $arg == "junit-dependencies" ]; then
3735
source ${CARGO_HOME}/env
38-
# Install tool for converting cargo test output to junit
39-
cargo install cargo2junit
4036

4137
# install npm/node
4238
./.evergreen/install-node.sh
4339

4440
source ./.evergreen/env.sh
4541

42+
# Install junit-compatible test runner
43+
cargo install cargo-nextest --locked
44+
4645
# Install tool for merging different junit reports into a single one
4746
set +o errexit
4847
set -o pipefail

.evergreen/run-atlas-tests.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ use_async_runtime
1010

1111
set +o errexit
1212

13-
cargo_test atlas_connectivity > results.xml
13+
cargo_test atlas_connectivity results.xml
1414

1515
exit $CARGO_RESULT

.evergreen/run-aws-tests.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ FEATURE_FLAGS+=("aws-auth")
4949

5050
set +o errexit
5151

52-
cargo_test auth_aws > auth_aws.xml
53-
cargo_test lambda_examples::auth::test_handler > lambda_handler.xml
52+
cargo_test auth_aws auth_aws.xml
53+
cargo_test lambda_examples::auth::test_handler lambda_handler.xml
5454

5555
junit-report-merger results.xml auth_aws.xml lambda_handler.xml
5656

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ FEATURE_FLAGS+=("aws-auth")
1111

1212
set +o errexit
1313

14-
cargo_test spec::auth > spec.xml
15-
cargo_test uri_options > uri_options.xml
16-
cargo_test connection_string > connection_string.xml
14+
cargo_test spec::auth spec.xml
15+
cargo_test uri_options uri_options.xml
16+
cargo_test connection_string connection_string.xml
1717

1818
junit-report-merger results.xml spec.xml uri_options.xml connection_string.xml
1919

.evergreen/run-csfle-tests.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ echo "cargo test options: $(cargo_test_options)"
2323

2424
set +o errexit
2525

26-
cargo_test test::csfle > prose.xml
27-
cargo_test test::spec::client_side_encryption > spec.xml
26+
cargo_test test::csfle prose.xml
27+
cargo_test test::spec::client_side_encryption spec.xml
2828

2929
# Unset variables for on-demand credential failure tests.
3030
unset AWS_ACCESS_KEY_ID
3131
unset AWS_SECRET_ACCESS_KEY
32-
cargo_test test::csfle::on_demand_aws_failure > failure.xml
32+
cargo_test test::csfle::on_demand_aws_failure failure.xml
3333

3434
junit-report-merger results.xml prose.xml spec.xml failure.xml
3535

.evergreen/run-oidc-tests.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ set -o xtrace
88

99
set +o errexit
1010

11-
cargo_test test::spec::oidc > prose.xml
11+
cargo_test test::spec::oidc prose.xml
1212

1313
junit-report-merger results.xml prose.xml
1414

.evergreen/run-plain-tests.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ source .evergreen/cargo-test.sh
88

99
set +o errexit
1010

11-
MONGO_PLAIN_AUTH_TEST=1 cargo_test plain > results.xml
11+
MONGO_PLAIN_AUTH_TEST=1 cargo_test plain results.xml
1212

1313
exit $CARGO_RESULT

.evergreen/run-serverless-tests.sh

+10-10
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@ export SERVERLESS="serverless"
1616

1717
set +o errexit
1818

19-
cargo_test test::spec::crud > crud.xml
20-
cargo_test test::spec::retryable_reads > retryable_reads.xml
21-
cargo_test test::spec::retryable_writes > retryable_writes.xml
22-
cargo_test test::spec::versioned_api > versioned_api.xml
23-
cargo_test test::spec::sessions > sessions.xml
24-
cargo_test test::spec::transactions > transactions.xml
25-
cargo_test test::spec::load_balancers > load_balancers.xml
26-
cargo_test test::cursor > cursor.xml
27-
cargo_test test::spec::collection_management > coll.xml
28-
cargo_test test::spec::command_monitoring_unified > monitoring.xml
19+
cargo_test test::spec::crud crud.xml
20+
cargo_test test::spec::retryable_reads retryable_reads.xml
21+
cargo_test test::spec::retryable_writes retryable_writes.xml
22+
cargo_test test::spec::versioned_api versioned_api.xml
23+
cargo_test test::spec::sessions sessions.xml
24+
cargo_test test::spec::transactions transactions.xml
25+
cargo_test test::spec::load_balancers load_balancers.xml
26+
cargo_test test::cursor cursor.xml
27+
cargo_test test::spec::collection_management coll.xml
28+
cargo_test test::spec::command_monitoring_unified monitoring.xml
2929

3030
junit-report-merger results.xml crud.xml retryable_reads.xml retryable_writes.xml versioned_api.xml sessions.xml transactions.xml load_balancers.xml cursor.xml coll.xml monitoring.xml
3131

.evergreen/run-tests.sh

+7-5
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,14 @@ echo "cargo test options: $(cargo_test_options)"
3434

3535
set +o errexit
3636

37-
cargo_test > async-tests.xml
37+
cargo_test "" async-tests.xml
3838
FEATURE_FLAGS+=("${SYNC_FEATURE}")
39-
cargo_test sync > sync-tests.xml
40-
CARGO_OPTIONS+=("--doc")
41-
cargo_test sync > sync-doc-tests.xml
39+
cargo_test sync sync-tests.xml
4240

43-
junit-report-merger results.xml async-tests.xml sync-tests.xml sync-doc-tests.xml
41+
junit-report-merger results.xml async-tests.xml sync-tests.xml
42+
43+
# cargo-nextest doesn't support doc tests
44+
RUST_BACKTRACE=1 cargo test --doc $(cargo_test_options)
45+
(( CARGO_RESULT = ${CARGO_RESULT} || $? ))
4446

4547
exit $CARGO_RESULT

.evergreen/run-x509-tests.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ FEATURE_FLAGS+=("${TLS_FEATURE}")
2121

2222
set +o errexit
2323

24-
MONGO_X509_USER="$SUBJECT" cargo_test > results.xml
24+
MONGO_X509_USER="$SUBJECT" cargo_test "" results.xml
2525

2626
exit ${CARGO_RESULT}

src/change_stream.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,12 @@ use crate::{
5050
///
5151
/// ```
5252
/// # #[cfg(all(not(feature = "sync"), not(feature = "tokio-sync")))]
53+
/// # {
5354
/// # use futures::stream::StreamExt;
5455
/// # use mongodb::{Client, error::Result, bson::doc,
5556
/// # change_stream::event::ChangeStreamEvent};
5657
/// # #[cfg(feature = "async-std-runtime")]
57-
/// # use async_std::task;
58+
/// # use async_std::{task, stream::StreamExt};
5859
/// # #[cfg(feature = "tokio-runtime")]
5960
/// # use tokio::task;
6061
/// #
@@ -73,6 +74,7 @@ use crate::{
7374
/// #
7475
/// # Ok(())
7576
/// # }
77+
/// # }
7678
/// ```
7779
///
7880
/// If a [`ChangeStream`] is still open when it goes out of scope, it will automatically be closed

src/lib.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
//! ## Using the async API
7373
//! ### Connecting to a MongoDB deployment
7474
//! ```no_run
75+
//! # #[cfg(not(any(feature = "sync", feature = "tokio-sync")))]
7576
//! # async fn foo() -> mongodb::error::Result<()> {
7677
//! use mongodb::{Client, options::ClientOptions};
7778
//!
@@ -218,7 +219,7 @@
218219
//! title: String,
219220
//! author: String,
220221
//! }
221-
//!
222+
//! # fn wrapper() -> mongodb::error::Result<()> {
222223
//! let client = Client::with_uri_str("mongodb://localhost:27017")?;
223224
//! let database = client.database("mydb");
224225
//! let collection = database.collection::<Book>("books");
@@ -245,6 +246,8 @@
245246
//! for result in cursor {
246247
//! println!("title: {}", result?.title);
247248
//! }
249+
//! # Ok(())
250+
//! # }
248251
//! # }
249252
//! ```
250253
//!

0 commit comments

Comments
 (0)