@@ -9,6 +9,7 @@ use tokio::sync::RwLockWriteGuard;
9
9
10
10
use crate :: {
11
11
error:: ErrorKind ,
12
+ sdam:: ServerType ,
12
13
test:: {
13
14
CmapEvent ,
14
15
Event ,
@@ -318,6 +319,7 @@ async fn auth_error() {
318
319
options. retry_writes = Some ( false ) ;
319
320
options. cmap_event_handler = Some ( handler. clone ( ) ) ;
320
321
options. command_event_handler = Some ( handler. clone ( ) ) ;
322
+ options. sdam_event_handler = Some ( handler. clone ( ) ) ;
321
323
let client = Client :: with_options ( options) . expect ( "client creation should succeed" ) ;
322
324
323
325
let coll = client. database ( "auth_error" ) . collection ( "auth_error" ) ;
@@ -327,18 +329,25 @@ async fn auth_error() {
327
329
. expect_err ( "insert should fail" ) ;
328
330
assert ! ( matches!( * auth_err. kind, ErrorKind :: Authentication { .. } ) ) ;
329
331
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
+
330
344
subscriber
331
345
. wait_for_event ( Duration :: from_millis ( 2000 ) , |event| {
332
346
matches ! ( event, Event :: Cmap ( CmapEvent :: PoolCleared ( _) ) )
333
347
} )
334
348
. await
335
349
. expect ( "should see pool cleared event" ) ;
336
350
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
-
342
351
coll. insert_many ( vec ! [ doc! { "_id" : 5 } , doc! { "_id" : 6 } ] , None )
343
352
. await
344
353
. expect ( "insert should succeed" ) ;
0 commit comments