Skip to content

Commit b9fcfa4

Browse files
RUST-949 Use SDAM monitoring in auth_error test
1 parent c9b829f commit b9fcfa4

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/sdam/test.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use tokio::sync::RwLockWriteGuard;
99

1010
use crate::{
1111
error::ErrorKind,
12+
sdam::ServerType,
1213
test::{
1314
CmapEvent,
1415
Event,
@@ -318,6 +319,7 @@ async fn auth_error() {
318319
options.retry_writes = Some(false);
319320
options.cmap_event_handler = Some(handler.clone());
320321
options.command_event_handler = Some(handler.clone());
322+
options.sdam_event_handler = Some(handler.clone());
321323
let client = Client::with_options(options).expect("client creation should succeed");
322324

323325
let coll = client.database("auth_error").collection("auth_error");
@@ -327,18 +329,25 @@ async fn auth_error() {
327329
.expect_err("insert should fail");
328330
assert!(matches!(*auth_err.kind, ErrorKind::Authentication { .. }));
329331

332+
if !setup_client.is_load_balanced() {
333+
subscriber
334+
.wait_for_event(Duration::from_millis(2000), |event| match event {
335+
Event::Sdam(SdamEvent::ServerDescriptionChanged(event)) => {
336+
event.new_description.description.server_type == ServerType::Unknown
337+
}
338+
_ => false,
339+
})
340+
.await
341+
.expect("should see server marked unknown");
342+
}
343+
330344
subscriber
331345
.wait_for_event(Duration::from_millis(2000), |event| {
332346
matches!(event, Event::Cmap(CmapEvent::PoolCleared(_)))
333347
})
334348
.await
335349
.expect("should see pool cleared event");
336350

337-
// Wait a little while for the server to be marked as Unknown.
338-
// Once we have SDAM monitoring, this wait can be removed and be replaced
339-
// with another event waiting.
340-
RUNTIME.delay_for(Duration::from_millis(750)).await;
341-
342351
coll.insert_many(vec![doc! { "_id": 5 }, doc! { "_id": 6 }], None)
343352
.await
344353
.expect("insert should succeed");

0 commit comments

Comments
 (0)