1
- use std:: { collections:: HashMap , time:: Duration } ;
1
+ use std:: { collections:: HashMap , sync :: Arc , time:: Duration } ;
2
2
3
3
use serde:: Deserialize ;
4
4
@@ -12,7 +12,7 @@ use crate::{
12
12
ServerType ,
13
13
TopologyDescription ,
14
14
} ,
15
- selection_criteria:: TagSet ,
15
+ selection_criteria:: { SelectionCriteria , TagSet } ,
16
16
} ;
17
17
18
18
mod in_window;
@@ -29,7 +29,7 @@ impl TestTopologyDescription {
29
29
fn into_topology_description (
30
30
self ,
31
31
heartbeat_frequency : Option < Duration > ,
32
- ) -> Option < TopologyDescription > {
32
+ ) -> TopologyDescription {
33
33
let servers: HashMap < ServerAddress , ServerDescription > = self
34
34
. servers
35
35
. into_iter ( )
@@ -53,7 +53,6 @@ impl TestTopologyDescription {
53
53
heartbeat_freq : heartbeat_frequency,
54
54
servers,
55
55
}
56
- . into ( )
57
56
}
58
57
}
59
58
@@ -184,3 +183,66 @@ fn is_master_response_from_server_type(server_type: ServerType) -> Option<IsMast
184
183
185
184
Some ( response)
186
185
}
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