@@ -472,13 +472,34 @@ impl TopologyWorker {
472
472
}
473
473
474
474
/// Update the topology using the provided `ServerDescription`.
475
- async fn update_server ( & mut self , sd : ServerDescription ) -> bool {
476
- let server_type = sd. server_type ;
477
- let server_address = sd. address . clone ( ) ;
478
-
475
+ async fn update_server ( & mut self , mut sd : ServerDescription ) -> bool {
479
476
let mut latest_state = self . borrow_latest_state ( ) . clone ( ) ;
480
477
let old_description = latest_state. description . clone ( ) ;
481
478
479
+ if let Some ( expected_name) = & self . options . repl_set_name {
480
+ let got_name = sd. set_name ( ) ;
481
+ if latest_state. description . topology_type ( ) == TopologyType :: Single
482
+ && got_name. as_ref ( ) . map ( |opt| opt. as_ref ( ) ) != Ok ( Some ( expected_name) )
483
+ {
484
+ let got_display = match got_name {
485
+ Ok ( Some ( s) ) => format ! ( "{:?}" , s) ,
486
+ Ok ( None ) => "<none>" . to_string ( ) ,
487
+ Err ( s) => format ! ( "<error: {}>" , s) ,
488
+ } ;
489
+ // Mark server as unknown.
490
+ sd = ServerDescription :: new (
491
+ sd. address ,
492
+ Some ( Err ( format ! (
493
+ "Connection string replicaSet name {:?} does not match actual name {}" ,
494
+ expected_name, got_display,
495
+ ) ) ) ,
496
+ ) ;
497
+ }
498
+ }
499
+
500
+ let server_type = sd. server_type ;
501
+ let server_address = sd. address . clone ( ) ;
502
+
482
503
// TODO: RUST-1270 change this method to not return a result.
483
504
let _ = latest_state. description . update ( sd) ;
484
505
0 commit comments