Skip to content

Commit 8afc1bd

Browse files
authored
RUST-1219, RUST-863: Assert that a ping succeeds in DNS seedlist tests; sync DB name with comma tests (#824)
1 parent 677fe85 commit 8afc1bd

File tree

61 files changed

+206
-98
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+206
-98
lines changed

src/test/spec/initial_dns_seedlist_discovery.rs

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use tokio::sync::RwLockReadGuard;
55

66
use crate::{
77
bson::doc,
8-
client::{auth::AuthMechanism, Client},
8+
client::Client,
99
options::{ClientOptions, ResolverConfig},
1010
runtime,
1111
test::{log_uncaptured, run_spec_test, TestClient, CLIENT_OPTIONS, LOCK},
@@ -25,6 +25,7 @@ struct TestFile {
2525
num_seeds: Option<usize>,
2626
#[serde(rename = "numHosts")]
2727
num_hosts: Option<usize>,
28+
ping: Option<bool>,
2829
}
2930

3031
#[derive(Debug, Deserialize, PartialEq)]
@@ -136,37 +137,19 @@ async fn run_test(mut test_file: TestFile) {
136137
"skipping initial_dns_seedlist_discovery test case due to TLS requirement mismatch",
137138
)
138139
} else {
139-
// If the connection URI provides authentication information, manually create the user
140-
// before connecting.
141-
if let Some(ParsedOptions {
142-
user: Some(ref user),
143-
password: Some(ref pwd),
144-
ref db,
145-
}) = test_file.parsed_options
146-
{
147-
client
148-
.drop_and_create_user(
149-
user,
150-
pwd.as_str(),
151-
&[],
152-
&[AuthMechanism::ScramSha1, AuthMechanism::ScramSha256],
153-
db.as_deref(),
154-
)
155-
.await
156-
.unwrap();
157-
}
158-
159140
let mut options_with_tls = options.clone();
160141
if requires_tls {
161142
options_with_tls.tls = CLIENT_OPTIONS.get().await.tls.clone();
162143
}
163144

164145
let client = Client::with_options(options_with_tls).unwrap();
165-
client
166-
.database("db")
167-
.run_command(doc! { "ping" : 1 }, None)
168-
.await
169-
.unwrap();
146+
if test_file.ping == Some(true) {
147+
client
148+
.database("db")
149+
.run_command(doc! { "ping" : 1 }, None)
150+
.await
151+
.unwrap();
152+
}
170153

171154
if let Some(ref mut hosts) = test_file.hosts {
172155
hosts.sort();

src/test/spec/json/initial-dns-seedlist-discovery/README.rst

Lines changed: 42 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -114,31 +114,49 @@ These YAML and JSON files contain the following fields:
114114
- ``error``: indicates that the parsing of the URI, or the resolving or
115115
contents of the SRV or TXT records included errors.
116116
- ``comment``: a comment to indicate why a test would fail.
117+
- ``ping``: if true, the test runner should run a "ping" operation after
118+
initializing a MongoClient.
117119

118120
.. _`Connection String`: ../../connection-string/connection-string-spec.rst
119121
.. _`URI options`: ../../uri-options/uri-options.rst
120122

121-
For each file, create a MongoClient initialized with the ``mongodb+srv``
122-
connection string.
123-
124-
If ``seeds`` is specified, drivers SHOULD verify that the set of hosts in the
125-
client's initial seedlist matches the list in ``seeds``. If ``numSeeds`` is
126-
specified, drivers SHOULD verify that the size of that set matches ``numSeeds``.
127-
128-
If ``hosts`` is specified, drivers MUST verify that the set of
129-
ServerDescriptions in the client's TopologyDescription eventually matches the
130-
list in ``hosts``. If ``numHosts`` is specified, drivers MUST verify that the
131-
size of that set matches ``numHosts``.
132-
133-
If ``options`` is specified, drivers MUST verify each of the values under
134-
``options`` match the MongoClient's parsed value for that option. There may be
135-
other options parsed by the MongoClient as well, which a test does not verify.
136-
137-
If ``parsed_options`` is specified, drivers MUST verify that each of the values
138-
under ``parsed_options`` match the MongoClient's parsed value for that option.
139-
Supported values include, but are not limited to, ``user`` and ``password``
140-
(parsed from ``UserInfo``) and ``auth_database`` (parsed from
141-
``Auth database``).
142-
143-
If ``error`` is specified and ``true``, drivers MUST verify that an error has
144-
been thrown.
123+
For each YAML file:
124+
125+
- Create a MongoClient initialized with the ``mongodb+srv``
126+
connection string.
127+
- Run run a "ping" operation if ``ping`` in the test file is true.
128+
129+
Assertions:
130+
131+
- If ``seeds`` is specified, drivers SHOULD verify that the set of hosts in the
132+
client's initial seedlist matches the list in ``seeds``. If ``numSeeds`` is
133+
specified, drivers SHOULD verify that the size of that set matches
134+
``numSeeds``.
135+
136+
- If ``hosts`` is specified, drivers MUST verify that the set of
137+
ServerDescriptions in the client's TopologyDescription eventually matches the
138+
list in ``hosts``. If ``numHosts`` is specified, drivers MUST verify that the
139+
size of that set matches ``numHosts``.
140+
141+
- If ``options`` is specified, drivers MUST verify each of the values under
142+
``options`` match the MongoClient's parsed value for that option. There may be
143+
other options parsed by the MongoClient as well, which a test does not verify.
144+
145+
- If ``parsed_options`` is specified, drivers MUST verify that each of the
146+
values under ``parsed_options`` match the MongoClient's parsed value for that
147+
option. Supported values include, but are not limited to, ``user`` and
148+
``password`` (parsed from ``UserInfo``) and ``auth_database`` (parsed from
149+
``Auth database``).
150+
151+
- If ``error`` is specified and ``true``, drivers MUST verify that initializing
152+
the MongoClient throws an error. If ``error`` is not specified or is
153+
``false``, both initializing the MongoClient and running a ping operation must
154+
succeed without throwing any errors.
155+
156+
- If ``ping`` is specified and ``true``, drivers MUST verify that running a
157+
"ping" operation using the initialized MongoClient succeeds. If ``ping`` is
158+
not specified or is ``false``, drivers MUST NOT run a "ping" operation.
159+
**Note:** These tests are expected to be run against MongoDB databases with
160+
and without authentication enabled. The "ping" operation does not require
161+
authentication so should succeed, even though the test URIs do not have
162+
correct authentication information.

src/test/spec/json/initial-dns-seedlist-discovery/load-balanced/loadBalanced-directConnection.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@
1010
"loadBalanced": true,
1111
"ssl": true,
1212
"directConnection": false
13-
}
13+
},
14+
"ping": true
1415
}

src/test/spec/json/initial-dns-seedlist-discovery/load-balanced/loadBalanced-directConnection.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ options:
1111
loadBalanced: true
1212
ssl: true
1313
directConnection: false
14+
ping: true

src/test/spec/json/initial-dns-seedlist-discovery/load-balanced/loadBalanced-true-txt.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@
99
"options": {
1010
"loadBalanced": true,
1111
"ssl": true
12-
}
12+
},
13+
"ping": true
1314
}

src/test/spec/json/initial-dns-seedlist-discovery/load-balanced/loadBalanced-true-txt.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ hosts:
88
options:
99
loadBalanced: true
1010
ssl: true
11+
ping: true

src/test/spec/json/initial-dns-seedlist-discovery/load-balanced/srvMaxHosts-zero-txt.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@
1010
"loadBalanced": true,
1111
"srvMaxHosts": 0,
1212
"ssl": true
13-
}
13+
},
14+
"ping": true
1415
}

src/test/spec/json/initial-dns-seedlist-discovery/load-balanced/srvMaxHosts-zero-txt.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ options:
88
loadBalanced: true
99
srvMaxHosts: 0
1010
ssl: true
11+
ping: true

src/test/spec/json/initial-dns-seedlist-discovery/load-balanced/srvMaxHosts-zero.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@
1010
"loadBalanced": true,
1111
"srvMaxHosts": 0,
1212
"ssl": true
13-
}
13+
},
14+
"ping": true
1415
}

src/test/spec/json/initial-dns-seedlist-discovery/load-balanced/srvMaxHosts-zero.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ options:
88
loadBalanced: true
99
srvMaxHosts: 0
1010
ssl: true
11+
ping: true

0 commit comments

Comments
 (0)