Skip to content

Commit 0deb71f

Browse files
RUST-2055 Use cargo-nextest to filter tests (#1303)
1 parent 3de1b74 commit 0deb71f

23 files changed

+277
-368
lines changed

.config/nextest.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
[profile.default]
22
test-threads = 1
3-
default-filter = 'not test(test::happy_eyeballs) and not test(kms_retry)'
3+
default-filter = 'not test(skip_local) and not test(skip_ci)'
44

55
[profile.ci]
66
failure-output = "final"
77
test-threads = 1
88
fail-fast = false
9-
default-filter = 'not test(test::happy_eyeballs)'
9+
default-filter = 'not test(skip_ci)'
1010

1111
[profile.ci.junit]
12-
path = "junit.xml"
12+
path = "junit.xml"

.evergreen/build-static-test-tarball.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ set -o pipefail
66
source ./.evergreen/env.sh
77

88
export RUSTFLAGS="-C target-feature=+crt-static"
9-
cargo test ${BUILD_FEATURES} --target x86_64-unknown-linux-gnu get_exe_name -- --ignored
9+
cargo test ${BUILD_FEATURES} --target x86_64-unknown-linux-gnu get_exe_name
1010
TEST_BINARY=$(cat exe_name.txt)
1111
TEST_TARBALL="/tmp/mongo-rust-driver.tar.gz"
1212
tar czvf ${TEST_TARBALL} ${TEST_BINARY} ./.evergreen
1313

1414
cat <<EOT > static-test-tarball-expansion.yml
1515
STATIC_TEST_BINARY: ${TEST_BINARY}
1616
STATIC_TEST_TARBALL: ${TEST_TARBALL}
17-
EOT
17+
EOT

.evergreen/config.yml

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -260,17 +260,6 @@ buildvariants:
260260
tasks:
261261
- name: test-x509-auth
262262

263-
- name: plain-auth
264-
display_name: "Plain Authentication"
265-
patchable: false
266-
run_on:
267-
- rhel87-small
268-
expansions:
269-
AUTH: auth
270-
SSL: ssl
271-
tasks:
272-
- test-plain-auth
273-
274263
- name: serverless
275264
display_name: "Serverless"
276265
run_on:
@@ -972,14 +961,6 @@ tasks:
972961
TOPOLOGY: server
973962
- func: "run x509 tests"
974963

975-
- name: test-plain-auth
976-
commands:
977-
- func: "bootstrap mongo-orchestration"
978-
vars:
979-
MONGODB_VERSION: rapid
980-
TOPOLOGY: server
981-
- func: "run plain tests"
982-
983964
- name: test-serverless
984965
commands:
985966
- func: "run serverless tests"
@@ -1417,17 +1398,6 @@ functions:
14171398
14181399
.evergreen/run-x509-tests.sh
14191400
1420-
"run plain tests":
1421-
- command: shell.exec
1422-
type: test
1423-
params:
1424-
working_dir: src
1425-
shell: bash
1426-
script: |
1427-
${PREPARE_SHELL}
1428-
1429-
.evergreen/run-plain-tests.sh
1430-
14311401
"prepare resources":
14321402
- command: subprocess.exec
14331403
params:
@@ -1694,7 +1664,7 @@ functions:
16941664
16951665
echo "Building test ... begin"
16961666
. ${PROJECT_DIRECTORY}/.evergreen/env.sh
1697-
cargo test get_exe_name --features in-use-encryption,gcp-kms -- --ignored
1667+
cargo test get_exe_name --features in-use-encryption,gcp-kms
16981668
cp $(cat exe_name.txt) test-contents/test-exe
16991669
echo "Building test ... end"
17001670
@@ -1963,7 +1933,7 @@ functions:
19631933
- command: expansions.update
19641934
params:
19651935
file: src/static-test-tarball-expansion.yml
1966-
1936+
19671937
"run oidc k8s test":
19681938
- command: subprocess.exec
19691939
params:

.evergreen/run-atlas-tests.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ set -o pipefail
66
source .evergreen/env.sh
77
source .evergreen/cargo-test.sh
88

9-
export MONGO_ATLAS_TESTS=1
9+
CARGO_OPTIONS+=("--ignore-default-filter")
1010

1111
source "${DRIVERS_TOOLS}/.evergreen/secrets_handling/setup-secrets.sh" drivers/atlas_connect
1212

1313
set +o errexit
1414

15-
cargo_test atlas_connectivity
15+
cargo_test test::atlas_connectivity
1616

1717
exit $CARGO_RESULT

.evergreen/run-aws-tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ FEATURE_FLAGS+=("aws-auth")
1818

1919
set +o errexit
2020

21-
cargo_test auth_aws
21+
cargo_test test::auth::aws
2222
cargo_test lambda_examples::auth::test_handler
2323
cargo_test spec::auth
2424
cargo_test uri_options

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

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

.evergreen/run-plain-tests.sh

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

.evergreen/run-search-index-test.sh

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@ set -o pipefail
66
source ./.evergreen/env.sh
77
source .evergreen/cargo-test.sh
88

9-
set -o xtrace
9+
CARGO_OPTIONS+=("--ignore-default-filter")
1010

11-
unset INDEX_MANAGEMENT_TEST_UNIFIED
12-
export INDEX_MANAGEMENT_TEST_PROSE=1
11+
set -o xtrace
1312

1413
set +o errexit
1514

16-
cargo_test test::spec::index_management
15+
cargo_test test::index_management::search_index
1716

18-
exit ${CARGO_RESULT}
17+
exit ${CARGO_RESULT}

.evergreen/run-tests.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ if [ "$SNAPPY" = true ]; then
2424
FEATURE_FLAGS+=("snappy-compression")
2525
fi
2626

27-
export SESSION_TEST_REQUIRE_MONGOCRYPTD=true
28-
export INDEX_MANAGEMENT_TEST_UNIFIED=1
29-
3027
echo "cargo test options: $(cargo_test_options)"
3128

3229
set +o errexit

src/test.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
#![allow(clippy::cast_possible_wrap)]
33

44
#[cfg(feature = "dns-resolver")]
5-
mod atlas_connectivity;
6-
mod atlas_planned_maintenance_testing;
7-
#[cfg(feature = "aws-auth")]
8-
mod auth_aws;
5+
#[path = "test/atlas_connectivity.rs"]
6+
mod atlas_connectivity_skip_ci; // requires Atlas URI environment variables set
7+
#[path = "test/atlas_planned_maintenance_testing.rs"]
8+
mod atlas_planned_maintenance_testing_skip_ci; // run from the drivers-atlas-testing project
9+
mod auth;
910
mod bulk_write;
1011
mod change_stream;
1112
mod client;
@@ -21,7 +22,8 @@ pub(crate) mod csfle;
2122
mod cursor;
2223
mod db;
2324
mod documentation_examples;
24-
mod happy_eyeballs;
25+
#[path = "test/happy_eyeballs.rs"]
26+
mod happy_eyeballs_skip_ci; // requires happy eyeballs server
2527
mod index_management;
2628
mod lambda_examples;
2729
pub(crate) mod spec;

src/test/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Test development guide
2+
3+
This document is a work-in-progress guide for developing tests for the driver.
4+
5+
## Filtering tests
6+
Tests that require any additional setup are filtered using cargo nextest's [filterset](https://nexte.st/docs/filtersets/). The driver uses two filters (configured in [nextest.toml](../../.config/nextest.toml)):
7+
8+
- `skip_local`: skips filtered tests when running locally.
9+
- `skip_ci`: skips filtered tests when running locally and in CI.
10+
11+
Filtered tests should be organized into modules with the desired filter at the end of the module name (e.g. `search_index_skip_ci`).
12+
13+
Filters can be bypassed locally by passing `--ignore-default-filter` to `cargo nextest run`. Filters can be bypassed in CI by adding the following to the script used to run the test:
14+
15+
```
16+
source .evergreen/cargo-test.sh
17+
CARGO_OPTIONS+=("--ignore-default-filter")
18+
```

src/test/atlas_connectivity.rs

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,20 @@
1-
use crate::{bson::doc, client::options::ResolverConfig, options::ClientOptions, Client};
2-
use bson::Document;
3-
4-
use super::log_uncaptured;
1+
use crate::{
2+
bson::{doc, Document},
3+
client::options::ResolverConfig,
4+
options::ClientOptions,
5+
Client,
6+
};
57

68
async fn run_test(uri_env_var: &str, resolver_config: Option<ResolverConfig>) {
7-
if std::env::var_os("MONGO_ATLAS_TESTS").is_none() {
8-
log_uncaptured(
9-
"skipping atlas_connectivity test due to undefined environment variable \
10-
MONGO_ATLAS_TESTS",
11-
);
12-
return;
13-
}
14-
15-
let uri = if let Some(uri) = std::env::var_os(uri_env_var) {
16-
uri
17-
} else {
18-
panic!("could not find variable {}", uri_env_var);
19-
};
9+
let uri = std::env::var(uri_env_var).expect(uri_env_var);
2010

21-
let uri_string = uri.to_string_lossy();
2211
let options = match resolver_config {
2312
Some(resolver_config) => {
24-
ClientOptions::parse(uri_string.as_ref())
13+
ClientOptions::parse(uri)
2514
.resolver_config(resolver_config)
2615
.await
2716
}
28-
None => ClientOptions::parse(uri_string.as_ref()).await,
17+
None => ClientOptions::parse(uri).await,
2918
}
3019
.expect("uri parsing should succeed");
3120
let client = Client::with_options(options).expect("option validation should succeed");

src/test/atlas_planned_maintenance_testing.rs

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// DRIVER_REPOSITORY and DRIVER_REVISION fields for the Rust axis in drivers-atlas-testing's
33
// evergreen config file can be updated to test against your branch.
44

5+
#[path = "atlas_planned_maintenance_testing/json_models.rs"]
56
mod json_models;
67

78
use std::{
@@ -28,28 +29,8 @@ use json_models::{Events, Results};
2829

2930
use super::spec::unified_runner::EntityMap;
3031

31-
#[test]
32-
#[ignore]
33-
fn get_exe_name() {
34-
let mut file = File::create("exe_name.txt").expect("Failed to create file");
35-
let exe_name = env::current_exe()
36-
.expect("Failed to determine name of test executable")
37-
.into_os_string()
38-
.into_string()
39-
.expect("Failed to convert OS string to string");
40-
write!(&mut file, "{}", exe_name).expect("Failed to write executable name to file");
41-
}
42-
4332
#[tokio::test]
4433
async fn workload_executor() {
45-
if env::var("ATLAS_PLANNED_MAINTENANCE_TESTING").is_err() {
46-
// This test should only be run from the workload-executor script.
47-
log_uncaptured(
48-
"Skipping workload_executor due to being run outside of planned maintenance testing",
49-
);
50-
return;
51-
}
52-
5334
let connection_string =
5435
env::var("WORKLOAD_EXECUTOR_CONNECTION_STRING").expect("No connection string specified");
5536

@@ -94,7 +75,7 @@ async fn execute_workload(test_runner: &mut TestRunner, workload: Value) -> Vec<
9475
fn write_json(entities: &mut EntityMap, mut errors: Vec<Bson>) {
9576
log_uncaptured("Writing planned maintenance test results to files");
9677

97-
let mut events = Events::new_empty();
78+
let mut events = Events::default();
9879
if let Some(Entity::Bson(Bson::Array(mut operation_errors))) = entities.remove("errors") {
9980
errors.append(&mut operation_errors);
10081
}

src/test/atlas_planned_maintenance_testing/json_models.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,12 @@ use serde_json::Number;
33

44
use crate::bson::Bson;
55

6-
#[derive(Serialize)]
6+
#[derive(Default, Serialize)]
77
pub(crate) struct Events {
88
pub(crate) errors: Vec<Bson>,
99
pub(crate) failures: Vec<Bson>,
1010
}
1111

12-
impl Events {
13-
pub(crate) fn new_empty() -> Self {
14-
Self {
15-
errors: vec![],
16-
failures: vec![],
17-
}
18-
}
19-
}
20-
2112
#[derive(Serialize)]
2213
#[serde(rename_all = "camelCase")]
2314
pub(crate) struct Results {

src/test/auth.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#[cfg(feature = "aws-auth")]
2+
mod aws;
3+
4+
use serde::Deserialize;
5+
6+
use crate::{
7+
bson::doc,
8+
options::{AuthMechanism, ClientOptions, Credential, ServerAddress},
9+
Client,
10+
};
11+
12+
#[tokio::test]
13+
async fn plain_auth() {
14+
let options = ClientOptions::builder()
15+
.hosts(vec![ServerAddress::Tcp {
16+
host: "ldaptest.10gen.cc".into(),
17+
port: None,
18+
}])
19+
.credential(
20+
Credential::builder()
21+
.mechanism(AuthMechanism::Plain)
22+
.username("drivers-team".to_string())
23+
.password("mongor0x$xgen".to_string())
24+
.build(),
25+
)
26+
.build();
27+
28+
let client = Client::with_options(options).unwrap();
29+
let coll = client.database("ldap").collection("test");
30+
31+
let doc = coll.find_one(doc! {}).await.unwrap().unwrap();
32+
33+
#[derive(Debug, Deserialize, PartialEq)]
34+
struct TestDocument {
35+
ldap: bool,
36+
authenticated: String,
37+
}
38+
39+
let doc: TestDocument = bson::from_document(doc).unwrap();
40+
41+
assert_eq!(
42+
doc,
43+
TestDocument {
44+
ldap: true,
45+
authenticated: "yeah".into()
46+
}
47+
);
48+
}

0 commit comments

Comments
 (0)