Skip to content

RUST-980 Run load balancer tests on evergreen, and update existing tests #477

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 34 commits into from
Oct 6, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
cf9ecc6
update env var names
abr-egn Sep 27, 2021
80e2e31
apply tls opts to MONGOS_LB_URI
abr-egn Sep 27, 2021
0e100e3
synthesize latency
abr-egn Sep 27, 2021
958c968
mock serviceId
abr-egn Sep 28, 2021
0127054
rustfmt
abr-egn Sep 28, 2021
c50f807
skip topology update for load balanced
abr-egn Sep 28, 2021
cebf3e9
skip tests using direct connections on load-balanced topologies
abr-egn Sep 28, 2021
2003f7a
properly initialize connection pool generation
abr-egn Sep 28, 2021
fd61488
set mock_service_id for global CLIENT_OPTIONS
abr-egn Sep 28, 2021
c784398
skip heartbeat_events test
abr-egn Sep 28, 2021
a90cfa5
preserve pool manager for pinned connections
abr-egn Sep 28, 2021
3800554
another place to set mock_service_id
abr-egn Sep 28, 2021
2733cda
skip versioned api examples
abr-egn Sep 28, 2021
30d54bc
always clear the waitqueue
abr-egn Sep 29, 2021
bd0d8c0
transactions
abr-egn Sep 29, 2021
a86b03b
rustfmt
abr-egn Sep 29, 2021
0f26622
clippy
abr-egn Sep 29, 2021
aa462e9
retryable-reads test updates
abr-egn Sep 29, 2021
f642c87
retryable-write test updates
abr-egn Sep 29, 2021
b833b88
evergreen config
abr-egn Sep 29, 2021
5cfb434
undo generate-uri.sh change
abr-egn Sep 29, 2021
a1afa9c
fix newline
abr-egn Sep 29, 2021
84a80cf
use lb uri for multiple mongoses in more places
abr-egn Sep 29, 2021
fbdc045
rustfmt
abr-egn Sep 29, 2021
0b01012
clippy
abr-egn Sep 29, 2021
da36f2b
evergreen fixes
abr-egn Sep 30, 2021
6d37ff9
more evergreen fixes
abr-egn Sep 30, 2021
b67f08b
evergreeeeeen
abr-egn Sep 30, 2021
251e784
attempt to exclude load_balancer tests on windows/arm
abr-egn Sep 30, 2021
6ee9a6d
typo
abr-egn Sep 30, 2021
63e116e
move lb uri var expansion later
abr-egn Sep 30, 2021
71b545b
more detailed dns resolution error message
abr-egn Sep 30, 2021
1b6a049
special-case 127.0.0.1 uris
abr-egn Sep 30, 2021
afe3a39
don't clear the queue when load balanced
abr-egn Oct 5, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
use lb uri for multiple mongoses in more places
  • Loading branch information
abr-egn committed Oct 6, 2021
commit 84a80cf49de6426cb49961b33a0e2747fdae9618
29 changes: 15 additions & 14 deletions src/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,7 @@ use std::{fs::read_to_string, str::FromStr};
const MAX_POOL_SIZE: u32 = 100;

lazy_static! {
pub(crate) static ref CLIENT_OPTIONS: ClientOptions = {
let uri = DEFAULT_URI.clone();
let mut options = ClientOptions::parse_without_srv_resolution(&uri).unwrap();
options.max_pool_size = Some(MAX_POOL_SIZE);
options.server_api = SERVER_API.clone();
if LOAD_BALANCED_SINGLE_URI
.as_ref()
.map_or(false, |uri| !uri.is_empty())
{
options.test_options_mut().mock_service_id = true;
}

options
};
pub(crate) static ref CLIENT_OPTIONS: ClientOptions = client_options_for_uri(&DEFAULT_URI);
pub(crate) static ref LOCK: TestLock = TestLock::new();
pub(crate) static ref DEFAULT_URI: String = get_default_uri();
pub(crate) static ref SERVER_API: Option<ServerApi> = match std::env::var("MONGODB_API_VERSION")
Expand All @@ -77,6 +64,20 @@ lazy_static! {
std::env::var("MULTI_MONGOS_LB_URI").ok();
}

pub(crate) fn client_options_for_uri(uri: &str) -> ClientOptions {
let mut options = ClientOptions::parse_without_srv_resolution(uri).unwrap();
options.max_pool_size = Some(MAX_POOL_SIZE);
options.server_api = SERVER_API.clone();
if LOAD_BALANCED_SINGLE_URI
.as_ref()
.map_or(false, |uri| !uri.is_empty())
{
options.test_options_mut().mock_service_id = true;
}

options
}

fn get_default_uri() -> String {
if let Some(uri) = LOAD_BALANCED_SINGLE_URI.clone() {
if !uri.is_empty() {
Expand Down
13 changes: 2 additions & 11 deletions src/test/util/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ use crate::{
},
},
options::ClientOptions,
test::{spec::ExpectedEventType, CLIENT_OPTIONS, LOCK},
test::{spec::ExpectedEventType, LOCK},
RUNTIME,
};

Expand Down Expand Up @@ -448,20 +448,11 @@ impl EventClient {
use_multiple_mongoses: Option<bool>,
event_handler: impl Into<Option<EventHandler>>,
) -> Self {
let mut options = match options.into() {
Some(mut options) => {
options.merge(CLIENT_OPTIONS.clone());
options
}
None => CLIENT_OPTIONS.clone(),
};
let mut options = TestClient::options_for_multiple_mongoses(options.into(), use_multiple_mongoses.unwrap_or(false)).await;
options
.test_options
.get_or_insert_with(Default::default)
.heartbeat_freq = heartbeat_freq;
if TestClient::new().await.is_sharded() && use_multiple_mongoses != Some(true) {
options.hosts = options.hosts.iter().cloned().take(1).collect();
}
EventClient::with_options_and_handler(options, event_handler).await
}

Expand Down
42 changes: 31 additions & 11 deletions src/test/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use crate::{
error::{CommandError, ErrorKind, Result},
operation::RunCommand,
options::{AuthMechanism, ClientOptions, CollectionOptions, CreateCollectionOptions},
test::{Topology, LOAD_BALANCED_SINGLE_URI},
test::{Topology, LOAD_BALANCED_SINGLE_URI, LOAD_BALANCED_MULTIPLE_URI, client_options_for_uri},
Client,
Collection,
};
Expand Down Expand Up @@ -127,16 +127,7 @@ impl TestClient {
options: Option<ClientOptions>,
use_multiple_mongoses: bool,
) -> Self {
let mut options = match options {
Some(mut options) => {
options.merge(CLIENT_OPTIONS.clone());
options
}
None => CLIENT_OPTIONS.clone(),
};
if !use_multiple_mongoses && Self::new().await.is_sharded() {
options.hosts = options.hosts.iter().cloned().take(1).collect();
}
let options = Self::options_for_multiple_mongoses(options, use_multiple_mongoses).await;
Self::with_options(Some(options)).await
}

Expand Down Expand Up @@ -364,6 +355,35 @@ impl TestClient {
}
.to_string()
}

pub async fn options_for_multiple_mongoses(options: Option<ClientOptions>, use_multiple_mongoses: bool) -> ClientOptions {
let is_load_balanced = options
.as_ref()
.and_then(|o| o.load_balanced)
.or_else(|| CLIENT_OPTIONS.load_balanced)
.unwrap_or(false);
let default_options = if is_load_balanced {
let uri = if use_multiple_mongoses {
LOAD_BALANCED_MULTIPLE_URI.as_ref().expect("MULTI_MONGOS_LB_URI is required")
} else {
LOAD_BALANCED_SINGLE_URI.as_ref().expect("SINGLE_MONGOS_LB_URI is required")
};
client_options_for_uri(uri)
} else {
CLIENT_OPTIONS.clone()
};
let mut options = match options {
Some(mut options) => {
options.merge(default_options);
options
}
None => default_options,
};
if Self::new().await.is_sharded() && !use_multiple_mongoses {
options.hosts = options.hosts.iter().cloned().take(1).collect();
}
options
}
}

pub async fn drop_collection<T>(coll: &Collection<T>)
Expand Down