Skip to content

Commit b7edc96

Browse files
RUST-1102 Run sync tests with #[test] attribute (#593)
1 parent a77eea9 commit b7edc96

File tree

26 files changed

+244
-370
lines changed

26 files changed

+244
-370
lines changed

src/bson_util/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,8 @@ pub(crate) fn read_document_bytes<R: Read>(mut reader: R) -> Result<Vec<u8>> {
217217
mod test {
218218
use crate::bson_util::num_decimal_digits;
219219

220-
#[cfg_attr(feature = "tokio-runtime", tokio::test)]
221-
#[cfg_attr(feature = "async-std-runtime", async_std::test)]
222-
async fn num_digits() {
220+
#[test]
221+
fn num_digits() {
223222
assert_eq!(num_decimal_digits(0), 1);
224223
assert_eq!(num_decimal_digits(1), 1);
225224
assert_eq!(num_decimal_digits(10), 2);

src/client/auth/scram.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -721,9 +721,8 @@ mod tests {
721721

722722
use super::ServerFirst;
723723

724-
#[cfg_attr(feature = "tokio-runtime", tokio::test)]
725-
#[cfg_attr(feature = "async-std-runtime", async_std::test)]
726-
async fn test_iteration_count() {
724+
#[test]
725+
fn test_iteration_count() {
727726
let nonce = "mocked";
728727

729728
let invalid_iteration_count = ServerFirst {

src/client/auth/test.rs

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@ lazy_static! {
1111
];
1212
}
1313

14-
#[cfg_attr(feature = "tokio-runtime", tokio::test)]
15-
#[cfg_attr(feature = "async-std-runtime", async_std::test)]
16-
async fn negotiate_both_scram() {
14+
#[test]
15+
fn negotiate_both_scram() {
1716
let description_both = StreamDescription {
1817
sasl_supported_mechs: Some(MECHS.to_vec()),
1918
..Default::default()
@@ -24,9 +23,8 @@ async fn negotiate_both_scram() {
2423
);
2524
}
2625

27-
#[cfg_attr(feature = "tokio-runtime", tokio::test)]
28-
#[cfg_attr(feature = "async-std-runtime", async_std::test)]
29-
async fn negotiate_sha1_only() {
26+
#[test]
27+
fn negotiate_sha1_only() {
3028
let description_sha1 = StreamDescription {
3129
sasl_supported_mechs: Some(MECHS[0..=0].to_vec()),
3230
..Default::default()
@@ -37,9 +35,8 @@ async fn negotiate_sha1_only() {
3735
);
3836
}
3937

40-
#[cfg_attr(feature = "tokio-runtime", tokio::test)]
41-
#[cfg_attr(feature = "async-std-runtime", async_std::test)]
42-
async fn negotiate_sha256_only() {
38+
#[test]
39+
fn negotiate_sha256_only() {
4340
let description_sha256 = StreamDescription {
4441
sasl_supported_mechs: Some(MECHS[1..=1].to_vec()),
4542
..Default::default()
@@ -50,19 +47,17 @@ async fn negotiate_sha256_only() {
5047
);
5148
}
5249

53-
#[cfg_attr(feature = "tokio-runtime", tokio::test)]
54-
#[cfg_attr(feature = "async-std-runtime", async_std::test)]
55-
async fn negotiate_none() {
50+
#[test]
51+
fn negotiate_none() {
5652
let description_none: StreamDescription = Default::default();
5753
assert_eq!(
5854
AuthMechanism::from_stream_description(&description_none),
5955
AuthMechanism::ScramSha1
6056
);
6157
}
6258

63-
#[cfg_attr(feature = "tokio-runtime", tokio::test)]
64-
#[cfg_attr(feature = "async-std-runtime", async_std::test)]
65-
async fn negotiate_mangled() {
59+
#[test]
60+
fn negotiate_mangled() {
6661
let description_mangled = StreamDescription {
6762
sasl_supported_mechs: Some(["NOT A MECHANISM".to_string(), "OTHER".to_string()].to_vec()),
6863
..Default::default()
@@ -89,16 +84,14 @@ fn scram_sasl_first_options(mechanism: AuthMechanism) {
8984
}
9085
}
9186

92-
#[cfg_attr(feature = "tokio-runtime", tokio::test)]
93-
#[cfg_attr(feature = "async-std-runtime", async_std::test)]
94-
async fn sasl_first_options_specified() {
87+
#[test]
88+
fn sasl_first_options_specified() {
9589
scram_sasl_first_options(AuthMechanism::ScramSha1);
9690
scram_sasl_first_options(AuthMechanism::ScramSha256);
9791
}
9892

99-
#[cfg_attr(feature = "tokio-runtime", tokio::test)]
100-
#[cfg_attr(feature = "async-std-runtime", async_std::test)]
101-
async fn sasl_first_options_not_specified() {
93+
#[test]
94+
fn sasl_first_options_not_specified() {
10295
let sasl_first = SaslStart::new(String::new(), AuthMechanism::MongoDbX509, Vec::new(), None);
10396
let command = sasl_first.into_command();
10497
assert!(

src/client/options/mod.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2334,10 +2334,6 @@ mod tests {
23342334
);
23352335
}
23362336

2337-
#[cfg_attr(feature = "tokio-runtime", tokio::test)]
2338-
#[cfg_attr(feature = "async-std-runtime", async_std::test)]
2339-
async fn with_invalid_read_preference_mode() {}
2340-
23412337
#[cfg_attr(feature = "tokio-runtime", tokio::test)]
23422338
#[cfg_attr(feature = "async-std-runtime", async_std::test)]
23432339
async fn with_mixed_options() {

src/operation/aggregate/test.rs

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,8 @@ fn build_test(
4040
assert_eq!(cmd_doc, expected_body);
4141
}
4242

43-
#[cfg_attr(feature = "tokio-runtime", tokio::test)]
44-
#[cfg_attr(feature = "async-std-runtime", async_std::test)]
45-
async fn build() {
43+
#[test]
44+
fn build() {
4645
let ns = Namespace {
4746
db: "test_db".to_string(),
4847
coll: "test_coll".to_string(),
@@ -74,9 +73,8 @@ async fn build() {
7473
build_test(ns, pipeline, Some(options), expected_body);
7574
}
7675

77-
#[cfg_attr(feature = "tokio-runtime", tokio::test)]
78-
#[cfg_attr(feature = "async-std-runtime", async_std::test)]
79-
async fn build_batch_size() {
76+
#[test]
77+
fn build_batch_size() {
8078
let ns = Namespace {
8179
db: "test_db".to_string(),
8280
coll: "test_coll".to_string(),
@@ -128,9 +126,8 @@ async fn build_batch_size() {
128126
build_test(ns, merge_pipeline, Some(batch_size_options), expected_body);
129127
}
130128

131-
#[cfg_attr(feature = "tokio-runtime", tokio::test)]
132-
#[cfg_attr(feature = "async-std-runtime", async_std::test)]
133-
async fn build_target() {
129+
#[test]
130+
fn build_target() {
134131
let pipeline = Vec::new();
135132

136133
let ns = Namespace {
@@ -155,9 +152,8 @@ async fn build_target() {
155152
build_test(ns.db, pipeline, None, expected_body);
156153
}
157154

158-
#[cfg_attr(feature = "tokio-runtime", tokio::test)]
159-
#[cfg_attr(feature = "async-std-runtime", async_std::test)]
160-
async fn build_max_await_time() {
155+
#[test]
156+
fn build_max_await_time() {
161157
let options = AggregateOptions::builder()
162158
.max_await_time(Duration::from_millis(5))
163159
.max_time(Duration::from_millis(10))
@@ -174,9 +170,8 @@ async fn build_max_await_time() {
174170
build_test("test_db".to_string(), Vec::new(), Some(options), body);
175171
}
176172

177-
#[cfg_attr(feature = "tokio-runtime", tokio::test)]
178-
#[cfg_attr(feature = "async-std-runtime", async_std::test)]
179-
async fn op_selection_criteria() {
173+
#[test]
174+
fn op_selection_criteria() {
180175
test::op_selection_criteria(|selection_criteria| {
181176
let options = AggregateOptions {
182177
selection_criteria,
@@ -186,9 +181,8 @@ async fn op_selection_criteria() {
186181
});
187182
}
188183

189-
#[cfg_attr(feature = "tokio-runtime", tokio::test)]
190-
#[cfg_attr(feature = "async-std-runtime", async_std::test)]
191-
async fn handle_max_await_time() {
184+
#[test]
185+
fn handle_max_await_time() {
192186
let response = doc! {
193187
"ok": 1,
194188
"cursor": {
@@ -211,9 +205,8 @@ async fn handle_max_await_time() {
211205
assert_eq!(spec.max_time(), Some(max_await));
212206
}
213207

214-
#[cfg_attr(feature = "tokio-runtime", tokio::test)]
215-
#[cfg_attr(feature = "async-std-runtime", async_std::test)]
216-
async fn handle_write_concern_error() {
208+
#[test]
209+
fn handle_write_concern_error() {
217210
let response = doc! {
218211
"ok": 1.0,
219212
"cursor": {
@@ -244,9 +237,8 @@ async fn handle_write_concern_error() {
244237
}
245238
}
246239

247-
#[cfg_attr(feature = "tokio-runtime", tokio::test)]
248-
#[cfg_attr(feature = "async-std-runtime", async_std::test)]
249-
async fn handle_invalid_response() {
240+
#[test]
241+
fn handle_invalid_response() {
250242
let aggregate = Aggregate::empty();
251243

252244
let garbled = doc! { "asdfasf": "ASdfasdf" };

src/operation/count/test.rs

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ use crate::{
1515
options::ReadConcernLevel,
1616
};
1717

18-
#[cfg_attr(feature = "tokio-runtime", tokio::test)]
19-
#[cfg_attr(feature = "async-std-runtime", async_std::test)]
20-
async fn build() {
18+
#[test]
19+
fn build() {
2120
let ns = Namespace {
2221
db: "test_db".to_string(),
2322
coll: "test_coll".to_string(),
@@ -35,9 +34,8 @@ async fn build() {
3534
assert_eq!(count_command.target_db, "test_db");
3635
}
3736

38-
#[cfg_attr(feature = "tokio-runtime", tokio::test)]
39-
#[cfg_attr(feature = "async-std-runtime", async_std::test)]
40-
async fn build_with_options() {
37+
#[test]
38+
fn build_with_options() {
4139
let read_concern: ReadConcern = ReadConcernLevel::Local.into();
4240
let max_time = Duration::from_millis(2_u64);
4341
let options: EstimatedDocumentCountOptions = EstimatedDocumentCountOptions::builder()
@@ -71,9 +69,8 @@ async fn build_with_options() {
7169
assert_eq!(cmd_doc, expected_body);
7270
}
7371

74-
#[cfg_attr(feature = "tokio-runtime", tokio::test)]
75-
#[cfg_attr(feature = "async-std-runtime", async_std::test)]
76-
async fn op_selection_criteria() {
72+
#[test]
73+
fn op_selection_criteria() {
7774
test::op_selection_criteria(|selection_criteria| {
7875
let options = EstimatedDocumentCountOptions {
7976
selection_criteria,
@@ -83,9 +80,8 @@ async fn op_selection_criteria() {
8380
});
8481
}
8582

86-
#[cfg_attr(feature = "tokio-runtime", tokio::test)]
87-
#[cfg_attr(feature = "async-std-runtime", async_std::test)]
88-
async fn handle_success() {
83+
#[test]
84+
fn handle_success() {
8985
let count_op = Count::empty();
9086

9187
let n = 26;
@@ -95,9 +91,8 @@ async fn handle_success() {
9591
assert_eq!(actual_values, n);
9692
}
9793

98-
#[cfg_attr(feature = "tokio-runtime", tokio::test)]
99-
#[cfg_attr(feature = "async-std-runtime", async_std::test)]
100-
async fn handle_success_agg() {
94+
#[test]
95+
fn handle_success_agg() {
10196
let count_op = Count::empty();
10297

10398
let n = 26;
@@ -116,9 +111,8 @@ async fn handle_success_agg() {
116111
assert_eq!(actual_values, n);
117112
}
118113

119-
#[cfg_attr(feature = "tokio-runtime", tokio::test)]
120-
#[cfg_attr(feature = "async-std-runtime", async_std::test)]
121-
async fn handle_response_no_n() {
114+
#[test]
115+
fn handle_response_no_n() {
122116
let count_op = Count::empty();
123117
handle_response_test(&count_op, doc! { "ok": 1.0 }).unwrap_err();
124118
}

src/operation/count_documents/test.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@ use crate::{
1313

1414
use super::CountDocuments;
1515

16-
#[cfg_attr(feature = "tokio-runtime", tokio::test)]
17-
#[cfg_attr(feature = "async-std-runtime", async_std::test)]
18-
async fn build() {
16+
#[test]
17+
fn build() {
1918
let ns = Namespace {
2019
db: "test_db".to_string(),
2120
coll: "test_coll".to_string(),
@@ -41,9 +40,8 @@ async fn build() {
4140
assert_eq!(count_command.target_db, "test_db");
4241
}
4342

44-
#[cfg_attr(feature = "tokio-runtime", tokio::test)]
45-
#[cfg_attr(feature = "async-std-runtime", async_std::test)]
46-
async fn build_with_options() {
43+
#[test]
44+
fn build_with_options() {
4745
let skip = 2;
4846
let limit = 5;
4947
let options = CountOptions::builder()
@@ -84,9 +82,8 @@ async fn build_with_options() {
8482
assert_eq!(cmd_doc, expected_body);
8583
}
8684

87-
#[cfg_attr(feature = "tokio-runtime", tokio::test)]
88-
#[cfg_attr(feature = "async-std-runtime", async_std::test)]
89-
async fn op_selection_criteria() {
85+
#[test]
86+
fn op_selection_criteria() {
9087
test::op_selection_criteria(|selection_criteria| {
9188
let options = CountOptions {
9289
selection_criteria,
@@ -96,9 +93,8 @@ async fn op_selection_criteria() {
9693
});
9794
}
9895

99-
#[cfg_attr(feature = "tokio-runtime", tokio::test)]
100-
#[cfg_attr(feature = "async-std-runtime", async_std::test)]
101-
async fn handle_success() {
96+
#[test]
97+
fn handle_success() {
10298
let ns = Namespace {
10399
db: "test_db".to_string(),
104100
coll: "test_coll".to_string(),

src/operation/create/test.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ use crate::{
88
Namespace,
99
};
1010

11-
#[cfg_attr(feature = "tokio-runtime", tokio::test)]
12-
#[cfg_attr(feature = "async-std-runtime", async_std::test)]
13-
async fn build() {
11+
#[test]
12+
fn build() {
1413
let mut op = Create::new(
1514
Namespace {
1615
db: "test_db".to_string(),
@@ -43,9 +42,8 @@ async fn build() {
4342
);
4443
}
4544

46-
#[cfg_attr(feature = "tokio-runtime", tokio::test)]
47-
#[cfg_attr(feature = "async-std-runtime", async_std::test)]
48-
async fn build_validator() {
45+
#[test]
46+
fn build_validator() {
4947
let query = doc! { "x": { "$gt": 1 } };
5048
let mut op = Create::new(
5149
Namespace {
@@ -72,16 +70,14 @@ async fn build_validator() {
7270
);
7371
}
7472

75-
#[cfg_attr(feature = "tokio-runtime", tokio::test)]
76-
#[cfg_attr(feature = "async-std-runtime", async_std::test)]
77-
async fn handle_success() {
73+
#[test]
74+
fn handle_success() {
7875
let op = Create::empty();
7976
handle_response_test(&op, doc! { "ok": 1.0 }).unwrap();
8077
}
8178

82-
#[cfg_attr(feature = "tokio-runtime", tokio::test)]
83-
#[cfg_attr(feature = "async-std-runtime", async_std::test)]
84-
async fn handle_write_concern_error() {
79+
#[test]
80+
fn handle_write_concern_error() {
8581
let op = Create::empty();
8682

8783
let response = doc! {

0 commit comments

Comments
 (0)