Skip to content

Commit 6bc8422

Browse files
Refactor spec test parser and runners (#841)
1 parent c8f4e5f commit 6bc8422

File tree

23 files changed

+393
-420
lines changed

23 files changed

+393
-420
lines changed

src/test/atlas_planned_maintenance_testing/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ async fn execute_workload(test_runner: &mut TestRunner, workload: Value) -> Vec<
8080

8181
log_uncaptured("Running planned maintenance tests");
8282

83-
if AssertUnwindSafe(test_runner.run_test(None, test_file, |_| true))
83+
if AssertUnwindSafe(test_runner.run_test(test_file, None, None))
8484
.catch_unwind()
8585
.await
8686
.is_err()

src/test/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub(crate) mod util;
2121
#[cfg(feature = "in-use-encryption-unstable")]
2222
pub(crate) use self::csfle::{KmsProviderList, KMS_PROVIDERS_MAP};
2323
pub(crate) use self::{
24-
spec::{run_single_test, run_spec_test, run_spec_test_with_path, RunOn, Serverless, Topology},
24+
spec::{run_spec_test, RunOn, Serverless, Topology},
2525
util::{
2626
assert_matches,
2727
eq_matches,

src/test/spec/change_streams.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
use crate::test::LOCK;
2-
3-
use super::{run_spec_test_with_path, run_unified_format_test};
1+
use crate::test::{spec::unified_runner::run_unified_tests, LOCK};
42

53
#[cfg_attr(feature = "tokio-runtime", tokio::test(flavor = "multi_thread"))] // multi_thread required for FailPoint
64
#[cfg_attr(feature = "async-std-runtime", async_std::test)]
7-
async fn run() {
5+
async fn run_unified() {
86
let _guard = LOCK.run_exclusively().await;
9-
run_spec_test_with_path(&["change-streams", "unified"], run_unified_format_test).await;
7+
run_unified_tests(&["change-streams", "unified"]).await;
108
}
Lines changed: 19 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,37 @@
11
use tokio::sync::RwLockWriteGuard;
22

3-
use crate::test::{log_uncaptured, LOCK};
4-
5-
use super::{
6-
run_spec_test_with_path,
7-
run_unified_format_test_filtered,
8-
run_v2_test,
9-
unified_runner::TestCase,
3+
use crate::test::{
4+
spec::{unified_runner::run_unified_tests, v2_runner::run_v2_tests},
5+
LOCK,
106
};
117

128
#[cfg_attr(feature = "tokio-runtime", tokio::test(flavor = "multi_thread"))]
139
#[cfg_attr(feature = "async-std-runtime", async_std::test)]
1410
async fn run_unified() {
1511
let _guard: RwLockWriteGuard<()> = LOCK.run_exclusively().await;
16-
run_spec_test_with_path(&["client-side-encryption", "unified"], |path, test| {
17-
run_unified_format_test_filtered(path, test, spec_predicate)
18-
})
19-
.await;
20-
}
2112

22-
#[allow(unused_variables)]
23-
fn spec_predicate(test: &TestCase) -> bool {
2413
#[cfg(not(feature = "openssl-tls"))]
25-
{
26-
if test.description == "create datakey with KMIP KMS provider" {
27-
crate::test::log_uncaptured(format!(
28-
"Skipping {:?}: KMIP test requires openssl-tls",
29-
test.description
30-
));
31-
return false;
32-
}
33-
}
34-
true
14+
let skipped_tests = &["create datakey with KMIP KMS provider"];
15+
#[cfg(feature = "openssl-tls")]
16+
let skipped_tests = &[];
17+
18+
run_unified_tests(&["client-side-encryption", "unified"])
19+
.skip_tests(skipped_tests)
20+
.await;
3521
}
3622

3723
#[cfg_attr(feature = "tokio-runtime", tokio::test(flavor = "multi_thread"))]
3824
#[cfg_attr(feature = "async-std-runtime", async_std::test)]
3925
async fn run_legacy() {
4026
let _guard: RwLockWriteGuard<()> = LOCK.run_exclusively().await;
4127

42-
run_spec_test_with_path(&["client-side-encryption", "legacy"], |path, test| async {
43-
// TODO RUST-582 Unskip this when we have csot implemented.
44-
if path.ends_with("timeoutMS.json") {
45-
log_uncaptured(format!(
46-
"Skipping {}: requires client side operations timeout",
47-
path.display()
48-
));
49-
return;
50-
}
51-
#[cfg(not(feature = "openssl-tls"))]
52-
if path.ends_with("kmipKMS.json") {
53-
log_uncaptured(format!(
54-
"Skipping {}: KMIP requires openssl",
55-
path.display()
56-
));
57-
return;
58-
}
59-
run_v2_test(path, test).await;
60-
})
61-
.await;
28+
// TODO RUST-528: Unskip timeoutMS.json when CSOT is implemented.
29+
#[cfg(not(feature = "openssl-tls"))]
30+
let skipped_files = &["timeoutMS.json", "kmipKMS.json"];
31+
#[cfg(feature = "openssl-tls")]
32+
let skipped_files = &["timeoutMS.json"];
33+
34+
run_v2_tests(&["client-side-encryption", "legacy"])
35+
.skip_files(skipped_files)
36+
.await;
6237
}
Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,11 @@
1-
use crate::test::{log_uncaptured, LOCK};
2-
3-
use super::{run_spec_test_with_path, run_unified_format_test};
1+
use crate::test::{spec::unified_runner::run_unified_tests, LOCK};
42

53
#[cfg_attr(feature = "tokio-runtime", tokio::test)]
64
#[cfg_attr(feature = "async-std-runtime", async_std::test)]
7-
async fn run() {
5+
async fn run_unified() {
86
let _guard = LOCK.run_exclusively().await;
9-
run_spec_test_with_path(&["collection-management"], |path, test| async {
10-
if path.ends_with("modifyCollection-pre_and_post_images.json") {
11-
// modifyCollection is unsupported.
12-
log_uncaptured("skipping modifyCollection-pre_and_post_images");
13-
return;
14-
}
15-
run_unified_format_test(path, test).await;
16-
})
17-
.await;
7+
run_unified_tests(&["collection-management"])
8+
// The driver does not support modifyCollection.
9+
.skip_files(&["modifyCollection-pre_and_post_images.json"])
10+
.await;
1811
}
Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
1-
use crate::test::LOCK;
2-
3-
use super::{run_spec_test_with_path, run_unified_format_test_filtered, unified_runner::TestCase};
1+
use crate::test::{spec::unified_runner::run_unified_tests, LOCK};
42

53
#[cfg_attr(feature = "tokio-runtime", tokio::test(flavor = "multi_thread"))]
64
#[cfg_attr(feature = "async-std-runtime", async_std::test)]
75
async fn command_monitoring_unified() {
86
let _guard = LOCK.run_exclusively().await;
9-
10-
let pred = |tc: &TestCase|
11-
// This test relies on old OP_QUERY behavior that many drivers still use for < 4.4, but we do not use, due to never implementing OP_QUERY.
12-
tc.description != "A successful find event with a getmore and the server kills the cursor (<= 4.4)";
13-
14-
run_spec_test_with_path(
15-
&["command-logging-and-monitoring", "monitoring"],
16-
|path, f| run_unified_format_test_filtered(path, f, pred),
17-
)
18-
.await;
7+
run_unified_tests(&["command-logging-and-monitoring", "monitoring"])
8+
.skip_tests(&[
9+
// This test relies on old OP_QUERY behavior that many drivers still use for < 4.4, but
10+
// we do not use, due to never implementing OP_QUERY.
11+
"A successful find event with a getmore and the server kills the cursor (<= 4.4)",
12+
])
13+
.await;
1914
}

src/test/spec/crud.rs

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,40 @@
11
use tokio::sync::RwLockWriteGuard;
22

3-
use crate::test::LOCK;
4-
5-
use super::{run_spec_test_with_path, run_unified_format_test_filtered, unified_runner::TestCase};
3+
use crate::test::{spec::unified_runner::run_unified_tests, LOCK};
64

75
#[cfg_attr(feature = "tokio-runtime", tokio::test(flavor = "multi_thread"))]
86
#[cfg_attr(feature = "async-std-runtime", async_std::test)]
9-
async fn run() {
7+
async fn run_unified() {
108
let _guard: RwLockWriteGuard<()> = LOCK.run_exclusively().await;
11-
run_spec_test_with_path(&["crud", "unified"], |path, file| {
12-
run_unified_format_test_filtered(path, file, test_predicate)
13-
})
14-
.await;
15-
}
16-
17-
fn test_predicate(test: &TestCase) -> bool {
18-
// The Rust driver doesn't support unacknowledged writes.
19-
let lower = test.description.to_lowercase();
20-
21-
!lower.contains("unacknowledged")
22-
// TODO: RUST-663: unskip aggregate $out and $merge tests
23-
&& !(lower.contains("aggregate with $out includes read preference for 5.0+ server"))
24-
&& !(lower.contains("aggregate with $out omits read preference for pre-5.0 server"))
25-
&& !(lower.contains("aggregate with $merge includes read preference for 5.0+ server"))
26-
&& !(lower.contains("aggregate with $merge omits read preference for pre-5.0 server"))
9+
run_unified_tests(&["crud", "unified"])
10+
.skip_files(&[
11+
// The Rust driver does not support unacknowledged writes (and does not intend to in
12+
// the future).
13+
"bulkWrite-deleteMany-hint-unacknowledged.json",
14+
"bulkWrite-deleteOne-hint-unacknowledged.json",
15+
"bulkWrite-replaceOne-hint-unacknowledged.json",
16+
"bulkWrite-updateMany-hint-unacknowledged.json",
17+
"bulkWrite-updateOne-hint-unacknowledged.json",
18+
"deleteMany-hint-unacknowledged.json",
19+
"deleteOne-hint-unacknowledged.json",
20+
"findOneAndDelete-hint-unacknowledged.json",
21+
"findOneAndReplace-hint-unacknowledged.json",
22+
"findOneAndUpdate-hint-unacknowledged.json",
23+
"replaceOne-hint-unacknowledged.json",
24+
"updateMany-hint-unacknowledged.json",
25+
"updateOne-hint-unacknowledged.json",
26+
])
27+
.skip_tests(&[
28+
// Unacknowledged write; see above.
29+
"Unacknowledged write using dollar-prefixed or dotted keys may be silently rejected \
30+
on pre-5.0 server",
31+
// TODO RUST-663: Unskip these tests.
32+
"Aggregate with $out includes read preference for 5.0+ server",
33+
"Aggregate with $out omits read preference for pre-5.0 server",
34+
"Aggregate with $merge includes read preference for 5.0+ server",
35+
"Aggregate with $merge omits read preference for pre-5.0 server",
36+
"Database-level aggregate with $out omits read preference for pre-5.0 server",
37+
"Database-level aggregate with $merge omits read preference for pre-5.0 server",
38+
])
39+
.await;
2740
}

src/test/spec/gridfs.rs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ use crate::{
99
options::{GridFsBucketOptions, GridFsUploadOptions},
1010
runtime,
1111
test::{
12-
run_spec_test_with_path,
13-
spec::unified_runner::{run_unified_format_test_filtered, TestCase},
12+
spec::unified_runner::run_unified_tests,
1413
FailCommandOptions,
1514
FailPoint,
1615
FailPointMode,
@@ -22,19 +21,14 @@ use crate::{
2221

2322
#[cfg_attr(feature = "tokio-runtime", tokio::test)]
2423
#[cfg_attr(feature = "async-std-runtime", async_std::test)]
25-
async fn run() {
24+
async fn run_unified() {
2625
let _guard = LOCK.run_concurrently().await;
27-
run_spec_test_with_path(&["gridfs"], |path, f| {
28-
run_unified_format_test_filtered(path, f, test_predicate)
29-
})
30-
.await;
31-
}
32-
33-
fn test_predicate(test: &TestCase) -> bool {
34-
let lower = test.description.to_lowercase();
35-
36-
// The Rust driver doesn't support the disableMD5 and contentType options for upload.
37-
!lower.contains("sans md5") && !lower.contains("contenttype")
26+
run_unified_tests(&["gridfs"])
27+
// The Rust driver doesn't support the disableMD5 option.
28+
.skip_files(&["upload-disableMD5.json"])
29+
// The Rust driver doesn't support the contentType option.
30+
.skip_tests(&["upload when contentType is provided"])
31+
.await;
3832
}
3933

4034
#[cfg_attr(feature = "tokio-runtime", tokio::test)]

src/test/spec/load_balancers.rs

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,23 @@
1-
use std::path::PathBuf;
2-
31
use tokio::sync::RwLockWriteGuard;
42

53
use crate::test::{
6-
run_spec_test_with_path,
74
spec::{
8-
run_unified_format_test,
9-
unified_runner::{ExpectedCmapEvent, ExpectedEvent, TestFile},
5+
unified_runner::{run_unified_tests, ExpectedCmapEvent, ExpectedEvent, TestFile},
106
ExpectedEventType,
117
},
128
LOCK,
139
};
1410

1511
#[cfg_attr(feature = "tokio-runtime", tokio::test(flavor = "multi_thread"))]
1612
#[cfg_attr(feature = "async-std-runtime", async_std::test)]
17-
async fn run() {
18-
async fn run_test(path: PathBuf, mut test_file: TestFile) {
19-
// The Rust driver doesn't support wait queue timeouts.
20-
if path.ends_with("wait-queue-timeouts.json") {
21-
return;
22-
}
23-
// The Rust driver's asynchronous check-in of connections means that sometimes a new
24-
// connection will be created, rather than re-using an existing one; the connectionReady
25-
// events generated by this cause tests to fail, but does not break user-visible behavior.
26-
// TODO RUST-1055 Remove this workaround.
13+
async fn run_unified() {
14+
let _guard: RwLockWriteGuard<()> = LOCK.run_exclusively().await;
15+
16+
// The Rust driver's asynchronous check-in of connections means that sometimes a new
17+
// connection will be created, rather than re-using an existing one; the connectionReady
18+
// events generated by this cause tests to fail, but does not break user-visible behavior.
19+
// TODO RUST-1055 Remove this workaround.
20+
fn file_transformation(test_file: &mut TestFile) {
2721
for test in &mut test_file.tests {
2822
if let Some(e) = test.expect_events.as_mut() {
2923
for expect_events in e {
@@ -40,8 +34,11 @@ async fn run() {
4034
}
4135
}
4236
}
43-
run_unified_format_test(path, test_file).await;
4437
}
45-
let _guard: RwLockWriteGuard<()> = LOCK.run_exclusively().await;
46-
run_spec_test_with_path(&["load-balancers"], run_test).await;
38+
39+
run_unified_tests(&["load-balancers"])
40+
// The Rust driver doesn't support wait queue timeouts.
41+
.skip_files(&["wait-queue-timeouts.json"])
42+
.transform_files(file_transformation)
43+
.await;
4744
}

0 commit comments

Comments
 (0)