Skip to content

Commit 1bf3b4b

Browse files
authored
RUST-1163 Fix load balancer tests (#576)
1 parent 8cc39e1 commit 1bf3b4b

File tree

9 files changed

+13
-71
lines changed

9 files changed

+13
-71
lines changed

.evergreen/config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ functions:
349349
AUTH=${AUTH} \
350350
SSL=${SSL} \
351351
REQUIRE_API_VERSION=${REQUIRE_API_VERSION} \
352+
LOAD_BALANCER=${LOAD_BALANCER} \
352353
sh ${DRIVERS_TOOLS}/.evergreen/run-orchestration.sh
353354
# run-orchestration generates expansion file with the MONGODB_URI for the cluster
354355
- command: expansions.update
@@ -883,6 +884,7 @@ tasks:
883884
vars:
884885
MONGODB_VERSION: "latest"
885886
TOPOLOGY: "sharded_cluster"
887+
LOAD_BALANCER: "true"
886888
- func: "start load balancer"
887889
- func: "run tests"
888890

src/client/options/mod.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -583,9 +583,6 @@ pub(crate) struct TestOptions {
583583

584584
/// Mock response for `SrvPollingMonitor::lookup_hosts`.
585585
pub(crate) mock_lookup_hosts: Option<Result<LookupHosts>>,
586-
587-
/// Mock the `serviceId` response for a load-balanced hello.
588-
pub(crate) mock_service_id: bool,
589586
}
590587

591588
fn default_hosts() -> Vec<ServerAddress> {

src/cmap/conn/wire/test.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@ use crate::{
66
bson::{doc, Bson},
77
cmap::options::StreamOptions,
88
runtime::AsyncStream,
9-
test::{CLIENT_OPTIONS, LOCK},
9+
test::{log_uncaptured, CLIENT_OPTIONS, LOCK},
1010
};
1111

1212
#[cfg_attr(feature = "tokio-runtime", tokio::test)]
1313
#[cfg_attr(feature = "async-std-runtime", async_std::test)]
1414
async fn basic() {
15-
if CLIENT_OPTIONS.tls_options().is_some() {
15+
if CLIENT_OPTIONS.tls_options().is_some() || CLIENT_OPTIONS.load_balanced.unwrap_or(false) {
16+
log_uncaptured("skipping conn::wire:basic test due to TLS and/or load balanced topology");
1617
return;
1718
}
1819

src/cmap/establish/handshake/mod.rs

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,6 @@ pub(crate) struct Handshaker {
144144
/// given the same pool options, so it can be created at the time the Handshaker is created.
145145
command: Command,
146146
credential: Option<Credential>,
147-
#[cfg(test)]
148-
mock_service_id: bool,
149147
// This field is not read without a compression feature flag turned on.
150148
#[allow(dead_code)]
151149
compressors: Option<Vec<Compressor>>,
@@ -162,9 +160,6 @@ impl Handshaker {
162160
let mut command =
163161
is_master_command(options.as_ref().and_then(|opts| opts.server_api.as_ref()));
164162

165-
#[cfg(test)]
166-
let mut mock_service_id = false;
167-
168163
if let Some(options) = options {
169164
if let Some(app_name) = options.app_name {
170165
metadata.application = Some(AppMetadata { name: app_name });
@@ -196,10 +191,7 @@ impl Handshaker {
196191
if options.load_balanced {
197192
command.body.insert("loadBalanced", true);
198193
}
199-
#[cfg(test)]
200-
{
201-
mock_service_id = options.mock_service_id;
202-
}
194+
203195
// Add compressors to handshake.
204196
// See https://github.com/mongodb/specifications/blob/master/source/compression/OP_COMPRESSED.rst
205197
if let Some(ref compressors) = options.compressors {
@@ -219,8 +211,6 @@ impl Handshaker {
219211
Self {
220212
command,
221213
credential,
222-
#[cfg(test)]
223-
mock_service_id,
224214
compressors,
225215
}
226216
}
@@ -237,24 +227,7 @@ impl Handshaker {
237227
let client_first = set_speculative_auth_info(&mut command.body, self.credential.as_ref())?;
238228

239229
let mut is_master_reply = run_is_master(conn, command, topology, handler).await?;
240-
// TODO PM-2369 Remove serviceId mocking when it's returned by the server.
241-
#[cfg(test)]
242-
{
243-
if self.command.body.contains_key("loadBalanced")
244-
&& is_master_reply.command_response.service_id.is_none()
245-
&& self.mock_service_id
246-
{
247-
is_master_reply.command_response.service_id = Some(
248-
is_master_reply
249-
.command_response
250-
.topology_version
251-
.as_ref()
252-
.unwrap()
253-
.get_object_id("processId")
254-
.unwrap(),
255-
);
256-
}
257-
}
230+
258231
if self.command.body.contains_key("loadBalanced")
259232
&& is_master_reply.command_response.service_id.is_none()
260233
{
@@ -326,8 +299,6 @@ pub(crate) struct HandshakerOptions {
326299
driver_info: Option<DriverInfo>,
327300
server_api: Option<ServerApi>,
328301
load_balanced: bool,
329-
#[cfg(test)]
330-
mock_service_id: bool,
331302
}
332303

333304
impl From<ConnectionPoolOptions> for HandshakerOptions {
@@ -339,8 +310,6 @@ impl From<ConnectionPoolOptions> for HandshakerOptions {
339310
driver_info: options.driver_info,
340311
server_api: options.server_api,
341312
load_balanced: options.load_balanced.unwrap_or(false),
342-
#[cfg(test)]
343-
mock_service_id: options.mock_service_id,
344313
}
345314
}
346315
}
@@ -354,8 +323,6 @@ impl From<ClientOptions> for HandshakerOptions {
354323
driver_info: options.driver_info,
355324
server_api: options.server_api,
356325
load_balanced: options.load_balanced.unwrap_or(false),
357-
#[cfg(test)]
358-
mock_service_id: options.test_options.map_or(false, |to| to.mock_service_id),
359326
}
360327
}
361328
}

src/cmap/options.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,6 @@ pub(crate) struct ConnectionPoolOptions {
9696

9797
/// Whether or not the client is connecting to a MongoDB cluster through a load balancer.
9898
pub(crate) load_balanced: Option<bool>,
99-
100-
/// Whether or not to mock the `serviceId` field of a hello through a load balancer.
101-
#[cfg(test)]
102-
#[serde(skip)]
103-
pub(crate) mock_service_id: bool,
10499
}
105100

106101
impl ConnectionPoolOptions {
@@ -122,11 +117,6 @@ impl ConnectionPoolOptions {
122117
#[cfg(test)]
123118
ready: None,
124119
load_balanced: options.load_balanced,
125-
#[cfg(test)]
126-
mock_service_id: options
127-
.test_options
128-
.as_ref()
129-
.map_or(false, |to| to.mock_service_id),
130120
}
131121
}
132122

src/test/mod.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,6 @@ pub(crate) fn update_options_for_testing(options: &mut ClientOptions) {
9090
if options.server_api.is_none() {
9191
options.server_api = SERVER_API.clone();
9292
}
93-
if LOAD_BALANCED_SINGLE_URI
94-
.as_ref()
95-
.map_or(false, |uri| !uri.is_empty())
96-
{
97-
options.test_options_mut().mock_service_id = true;
98-
}
9993
if options.compressors.is_none() {
10094
options.compressors = get_compressors();
10195
}

src/test/spec/connection_stepdown.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::{
1515
InsertManyOptions,
1616
WriteConcern,
1717
},
18-
test::{log_uncaptured, util::EventClient, LOCK},
18+
test::{log_uncaptured, util::EventClient, CLIENT_OPTIONS, LOCK},
1919
Collection,
2020
Database,
2121
RUNTIME,
@@ -27,7 +27,10 @@ async fn run_test<F: Future>(
2727
) {
2828
let _guard: RwLockWriteGuard<()> = LOCK.run_exclusively().await;
2929

30-
let options = ClientOptions::builder().retry_writes(false).build();
30+
let options = ClientOptions::builder()
31+
.hosts(CLIENT_OPTIONS.hosts.clone())
32+
.retry_writes(false)
33+
.build();
3134
let client = EventClient::with_additional_options(Some(options), None, None, None).await;
3235

3336
if !client.is_replica_set() {

src/test/spec/unified_runner/test_runner.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,7 @@ impl TestRunner {
114114
options.command_event_handler = Some(observer.clone());
115115
options.cmap_event_handler = Some(observer.clone());
116116
options.server_api = server_api;
117-
if LOAD_BALANCED_SINGLE_URI
118-
.as_ref()
119-
.map_or(false, |uri| !uri.is_empty())
120-
{
121-
options.test_options_mut().mock_service_id = true;
122-
}
117+
123118
if TestClient::new().await.is_sharded() {
124119
match client.use_multiple_mongoses {
125120
Some(true) => {

src/test/util/mod.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,6 @@ impl TestClient {
7373
options.sdam_event_handler = Some(handler);
7474
}
7575

76-
if LOAD_BALANCED_SINGLE_URI
77-
.as_ref()
78-
.map_or(false, |uri| !uri.is_empty())
79-
{
80-
options.test_options_mut().mock_service_id = true;
81-
}
82-
8376
let client = Client::with_options(options.clone()).unwrap();
8477

8578
// To avoid populating the session pool with leftover implicit sessions, we check out a

0 commit comments

Comments
 (0)