1- use std:: { collections:: HashMap , time:: Duration } ;
1+ use std:: { collections:: HashMap , sync :: Arc , time:: Duration } ;
22
33use serde:: Deserialize ;
44
@@ -12,7 +12,7 @@ use crate::{
1212 ServerType ,
1313 TopologyDescription ,
1414 } ,
15- selection_criteria:: TagSet ,
15+ selection_criteria:: { SelectionCriteria , TagSet } ,
1616} ;
1717
1818mod in_window;
@@ -29,7 +29,7 @@ impl TestTopologyDescription {
2929 fn into_topology_description (
3030 self ,
3131 heartbeat_frequency : Option < Duration > ,
32- ) -> Option < TopologyDescription > {
32+ ) -> TopologyDescription {
3333 let servers: HashMap < ServerAddress , ServerDescription > = self
3434 . servers
3535 . into_iter ( )
@@ -53,7 +53,6 @@ impl TestTopologyDescription {
5353 heartbeat_freq : heartbeat_frequency,
5454 servers,
5555 }
56- . into ( )
5756 }
5857}
5958
@@ -184,3 +183,66 @@ fn is_master_response_from_server_type(server_type: ServerType) -> Option<IsMast
184183
185184 Some ( response)
186185}
186+
187+ #[ test]
188+ fn predicate_omits_unavailable ( ) {
189+ let criteria = SelectionCriteria :: Predicate ( Arc :: new ( |si| {
190+ !matches ! ( si. server_type( ) , ServerType :: RsPrimary )
191+ } ) ) ;
192+
193+ let desc = TestTopologyDescription {
194+ topology_type : TopologyType :: ReplicaSetWithPrimary ,
195+ servers : vec ! [
196+ TestServerDescription {
197+ address: "localhost:27017" . to_string( ) ,
198+ avg_rtt_ms: Some ( 12.0 ) ,
199+ server_type: TestServerType :: RsPrimary ,
200+ tags: None ,
201+ last_update_time: None ,
202+ last_write: None ,
203+ _max_wire_version: None ,
204+ } ,
205+ TestServerDescription {
206+ address: "localhost:27018" . to_string( ) ,
207+ avg_rtt_ms: Some ( 12.0 ) ,
208+ server_type: TestServerType :: Unknown ,
209+ tags: None ,
210+ last_update_time: None ,
211+ last_write: None ,
212+ _max_wire_version: None ,
213+ } ,
214+ TestServerDescription {
215+ address: "localhost:27019" . to_string( ) ,
216+ avg_rtt_ms: Some ( 12.0 ) ,
217+ server_type: TestServerType :: RsArbiter ,
218+ tags: None ,
219+ last_update_time: None ,
220+ last_write: None ,
221+ _max_wire_version: None ,
222+ } ,
223+ TestServerDescription {
224+ address: "localhost:27020" . to_string( ) ,
225+ avg_rtt_ms: Some ( 12.0 ) ,
226+ server_type: TestServerType :: RsGhost ,
227+ tags: None ,
228+ last_update_time: None ,
229+ last_write: None ,
230+ _max_wire_version: None ,
231+ } ,
232+ TestServerDescription {
233+ address: "localhost:27021" . to_string( ) ,
234+ avg_rtt_ms: Some ( 12.0 ) ,
235+ server_type: TestServerType :: RsOther ,
236+ tags: None ,
237+ last_update_time: None ,
238+ last_write: None ,
239+ _max_wire_version: None ,
240+ } ,
241+ ] ,
242+ }
243+ . into_topology_description ( None ) ;
244+ pretty_assertions:: assert_eq!(
245+ desc. suitable_servers_in_latency_window( & criteria) . unwrap( ) ,
246+ Vec :: <& ServerDescription >:: new( )
247+ ) ;
248+ }
0 commit comments