|
1 |
| -mod event; |
2 |
| -mod operation; |
| 1 | +use crate::test::{spec::run_spec_test, LOCK}; |
3 | 2 |
|
4 |
| -use std::convert::Into; |
5 |
| - |
6 |
| -use semver::VersionReq; |
7 |
| -use serde::Deserialize; |
8 |
| -use tokio::sync::RwLockWriteGuard; |
9 |
| - |
10 |
| -use self::{event::TestEvent, operation::*}; |
11 |
| -use crate::{ |
12 |
| - bson::{Bson, Document}, |
13 |
| - options::ClientOptions, |
14 |
| - test::{assert_matches, log_uncaptured, util::TestClient, EventClient, CLIENT_OPTIONS, LOCK}, |
15 |
| -}; |
16 |
| - |
17 |
| -#[derive(Deserialize)] |
18 |
| -struct TestFile { |
19 |
| - data: Vec<Document>, |
20 |
| - collection_name: String, |
21 |
| - database_name: String, |
22 |
| - tests: Vec<TestCase>, |
23 |
| -} |
24 |
| - |
25 |
| -#[derive(Deserialize)] |
26 |
| -struct TestCase { |
27 |
| - description: String, |
28 |
| - #[serde(rename = "ignore_if_server_version_greater_than", default)] |
29 |
| - max_version: Option<String>, |
30 |
| - #[serde(rename = "ignore_if_server_version_less_than", default)] |
31 |
| - min_version: Option<String>, |
32 |
| - operation: Document, |
33 |
| - expectations: Vec<TestEvent>, |
34 |
| -} |
35 |
| - |
36 |
| -async fn run_command_monitoring_test(test_file: TestFile) { |
37 |
| - let _guard: RwLockWriteGuard<()> = LOCK.run_exclusively().await; |
38 |
| - |
39 |
| - let client = TestClient::new().await; |
40 |
| - |
41 |
| - let skipped_tests = vec![ |
42 |
| - // uses old count |
43 |
| - "A successful command", |
44 |
| - "A failed command event", |
45 |
| - "A successful command with a non-primary read preference", |
46 |
| - // bulk write not implemented |
47 |
| - "A successful mixed bulk write", |
48 |
| - "A successful unordered bulk write with an unacknowledged write concern", |
49 |
| - // We can't pass this test since it relies on old OP_QUERY behavior (SPEC-1519) |
50 |
| - "A successful find event with a getmore and the server kills the cursor (<= 4.4)", |
51 |
| - ]; |
52 |
| - |
53 |
| - for test_case in test_file.tests { |
54 |
| - if skipped_tests.iter().any(|st| st == &test_case.description) { |
55 |
| - log_uncaptured(format!("Skipping {}", test_case.description)); |
56 |
| - continue; |
57 |
| - } |
58 |
| - |
59 |
| - if let Some(ref max_version) = test_case.max_version { |
60 |
| - let req = VersionReq::parse(&format!("<= {}", &max_version)).unwrap(); |
61 |
| - if !req.matches(&client.server_version) { |
62 |
| - log_uncaptured(format!("Skipping {}", test_case.description)); |
63 |
| - continue; |
64 |
| - } |
65 |
| - } |
66 |
| - |
67 |
| - if let Some(ref min_version) = test_case.min_version { |
68 |
| - let req = VersionReq::parse(&format!(">= {}", &min_version)).unwrap(); |
69 |
| - if !req.matches(&client.server_version) { |
70 |
| - log_uncaptured(format!("Skipping {}", test_case.description)); |
71 |
| - continue; |
72 |
| - } |
73 |
| - } |
74 |
| - |
75 |
| - println!("Running {}", test_case.description); |
76 |
| - |
77 |
| - let operation: AnyTestOperation = |
78 |
| - bson::from_bson(Bson::Document(test_case.operation)).unwrap(); |
79 |
| - |
80 |
| - client |
81 |
| - .init_db_and_coll(&test_file.database_name, &test_file.collection_name) |
82 |
| - .await |
83 |
| - .insert_many(test_file.data.clone(), None) |
84 |
| - .await |
85 |
| - .expect("insert many error"); |
86 |
| - |
87 |
| - let options = ClientOptions::builder() |
88 |
| - .retry_writes(false) |
89 |
| - .hosts(CLIENT_OPTIONS.get().await.hosts.clone()) |
90 |
| - .build(); |
91 |
| - let client = |
92 |
| - EventClient::with_additional_options(Some(options), None, Some(false), None).await; |
93 |
| - |
94 |
| - let events: Vec<TestEvent> = client |
95 |
| - .run_operation_with_events( |
96 |
| - operation, |
97 |
| - &test_file.database_name, |
98 |
| - &test_file.collection_name, |
99 |
| - ) |
100 |
| - .await |
101 |
| - .into_iter() |
102 |
| - .map(Into::into) |
103 |
| - .collect(); |
104 |
| - |
105 |
| - assert_eq!(events.len(), test_case.expectations.len()); |
106 |
| - for (actual_event, expected_event) in events.iter().zip(test_case.expectations.iter()) { |
107 |
| - assert_matches(actual_event, expected_event, None); |
108 |
| - } |
109 |
| - } |
110 |
| -} |
111 |
| - |
112 |
| -#[cfg_attr(feature = "tokio-runtime", tokio::test)] |
113 |
| -#[cfg_attr(feature = "async-std-runtime", async_std::test)] |
114 |
| -async fn command_monitoring_legacy() { |
115 |
| - crate::test::run_spec_test( |
116 |
| - &["command-monitoring", "legacy"], |
117 |
| - run_command_monitoring_test, |
118 |
| - ) |
119 |
| - .await; |
120 |
| -} |
| 3 | +use super::{run_unified_format_test_filtered, unified_runner::TestCase}; |
121 | 4 |
|
122 | 5 | #[cfg_attr(feature = "tokio-runtime", tokio::test)]
|
123 | 6 | #[cfg_attr(feature = "async-std-runtime", async_std::test)]
|
124 | 7 | async fn command_monitoring_unified() {
|
125 |
| - crate::test::run_spec_test( |
126 |
| - &["command-monitoring", "unified"], |
127 |
| - super::run_unified_format_test, |
128 |
| - ) |
| 8 | + 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(&["command-monitoring", "unified"], |f| { |
| 15 | + run_unified_format_test_filtered(f, pred) |
| 16 | + }) |
129 | 17 | .await;
|
130 | 18 | }
|
0 commit comments