@@ -6,7 +6,7 @@ use crate::{
6
6
error:: Result ,
7
7
event:: command:: CommandEvent ,
8
8
options:: ReadConcern ,
9
- test:: log_uncaptured,
9
+ test:: { log_uncaptured, topology_is_standalone } ,
10
10
Client ,
11
11
ClientSession ,
12
12
Collection ,
@@ -118,31 +118,29 @@ fn all_session_ops() -> impl Iterator<Item = Operation> {
118
118
/// Test 1 from the causal consistency specification.
119
119
#[ tokio:: test]
120
120
async fn new_session_operation_time_null ( ) {
121
- let client = Client :: for_test ( ) . monitor_events ( ) . await ;
122
-
123
- if client. is_standalone ( ) {
121
+ if topology_is_standalone ( ) . await {
124
122
log_uncaptured (
125
123
"skipping new_session_operation_time_null due to unsupported topology: standalone" ,
126
124
) ;
127
125
return ;
128
126
}
129
127
128
+ let client = Client :: for_test ( ) . monitor_events ( ) . await ;
130
129
let session = client. start_session ( ) . await . unwrap ( ) ;
131
130
assert ! ( session. operation_time( ) . is_none( ) ) ;
132
131
}
133
132
134
133
/// Test 2 from the causal consistency specification.
135
134
#[ tokio:: test]
136
- async fn first_read_no_after_cluser_time ( ) {
137
- let client = Client :: for_test ( ) . monitor_events ( ) . await ;
138
-
139
- if client. is_standalone ( ) {
135
+ async fn first_read_no_after_cluster_time ( ) {
136
+ if topology_is_standalone ( ) . await {
140
137
log_uncaptured (
141
138
"skipping first_read_no_after_cluser_time due to unsupported topology: standalone" ,
142
139
) ;
143
140
return ;
144
141
}
145
142
143
+ let client = Client :: for_test ( ) . monitor_events ( ) . await ;
146
144
for op in all_session_ops ( ) . filter ( |o| o. is_read ) {
147
145
client. events . clone ( ) . clear_cached_events ( ) ;
148
146
@@ -172,13 +170,12 @@ async fn first_read_no_after_cluser_time() {
172
170
/// Test 3 from the causal consistency specification.
173
171
#[ tokio:: test]
174
172
async fn first_op_update_op_time ( ) {
175
- let client = Client :: for_test ( ) . monitor_events ( ) . await ;
176
-
177
- if client. is_standalone ( ) {
173
+ if topology_is_standalone ( ) . await {
178
174
log_uncaptured ( "skipping first_op_update_op_time due to unsupported topology: standalone" ) ;
179
175
return ;
180
176
}
181
177
178
+ let client = Client :: for_test ( ) . monitor_events ( ) . await ;
182
179
for op in all_session_ops ( ) {
183
180
client. events . clone ( ) . clear_cached_events ( ) ;
184
181
@@ -221,15 +218,15 @@ async fn first_op_update_op_time() {
221
218
/// Test 4 from the causal consistency specification.
222
219
#[ tokio:: test]
223
220
async fn read_includes_after_cluster_time ( ) {
224
- let client = Client :: for_test ( ) . monitor_events ( ) . await ;
225
-
226
- if client. is_standalone ( ) {
221
+ if topology_is_standalone ( ) . await {
227
222
log_uncaptured (
228
223
"skipping read_includes_after_cluster_time due to unsupported topology: standalone" ,
229
224
) ;
230
225
return ;
231
226
}
232
227
228
+ let client = Client :: for_test ( ) . monitor_events ( ) . await ;
229
+
233
230
let coll = client
234
231
. create_fresh_collection ( "causal_consistency_4" , "causal_consistency_4" , None )
235
232
. await ;
@@ -262,16 +259,15 @@ async fn read_includes_after_cluster_time() {
262
259
/// Test 5 from the causal consistency specification.
263
260
#[ tokio:: test]
264
261
async fn find_after_write_includes_after_cluster_time ( ) {
265
- let client = Client :: for_test ( ) . monitor_events ( ) . await ;
266
-
267
- if client. is_standalone ( ) {
262
+ if topology_is_standalone ( ) . await {
268
263
log_uncaptured (
269
264
"skipping find_after_write_includes_after_cluster_time due to unsupported topology: \
270
265
standalone",
271
266
) ;
272
267
return ;
273
268
}
274
269
270
+ let client = Client :: for_test ( ) . monitor_events ( ) . await ;
275
271
let coll = client
276
272
. create_fresh_collection ( "causal_consistency_5" , "causal_consistency_5" , None )
277
273
. await ;
@@ -306,16 +302,15 @@ async fn find_after_write_includes_after_cluster_time() {
306
302
/// Test 6 from the causal consistency specification.
307
303
#[ tokio:: test]
308
304
async fn not_causally_consistent_omits_after_cluster_time ( ) {
309
- let client = Client :: for_test ( ) . monitor_events ( ) . await ;
310
-
311
- if client. is_standalone ( ) {
305
+ if topology_is_standalone ( ) . await {
312
306
log_uncaptured (
313
307
"skipping not_causally_consistent_omits_after_cluster_time due to unsupported \
314
308
topology: standalone",
315
309
) ;
316
310
return ;
317
311
}
318
312
313
+ let client = Client :: for_test ( ) . monitor_events ( ) . await ;
319
314
let coll = client
320
315
. create_fresh_collection ( "causal_consistency_6" , "causal_consistency_6" , None )
321
316
. await ;
@@ -345,13 +340,12 @@ async fn not_causally_consistent_omits_after_cluster_time() {
345
340
/// Test 7 from the causal consistency specification.
346
341
#[ tokio:: test]
347
342
async fn omit_after_cluster_time_standalone ( ) {
348
- let client = Client :: for_test ( ) . monitor_events ( ) . await ;
349
-
350
- if !client. is_standalone ( ) {
343
+ if !topology_is_standalone ( ) . await {
351
344
log_uncaptured ( "skipping omit_after_cluster_time_standalone due to unsupported topology" ) ;
352
345
return ;
353
346
}
354
347
348
+ let client = Client :: for_test ( ) . monitor_events ( ) . await ;
355
349
let coll = client
356
350
. create_fresh_collection ( "causal_consistency_7" , "causal_consistency_7" , None )
357
351
. await ;
@@ -381,15 +375,14 @@ async fn omit_after_cluster_time_standalone() {
381
375
/// Test 8 from the causal consistency specification.
382
376
#[ tokio:: test]
383
377
async fn omit_default_read_concern_level ( ) {
384
- let client = Client :: for_test ( ) . monitor_events ( ) . await ;
385
-
386
- if client. is_standalone ( ) {
378
+ if topology_is_standalone ( ) . await {
387
379
log_uncaptured (
388
380
"skipping omit_default_read_concern_level due to unsupported topology: standalone" ,
389
381
) ;
390
382
return ;
391
383
}
392
384
385
+ let client = Client :: for_test ( ) . monitor_events ( ) . await ;
393
386
let coll = client
394
387
. create_fresh_collection ( "causal_consistency_8" , "causal_consistency_8" , None )
395
388
. await ;
@@ -421,15 +414,15 @@ async fn omit_default_read_concern_level() {
421
414
/// Test 9 from the causal consistency specification.
422
415
#[ tokio:: test]
423
416
async fn test_causal_consistency_read_concern_merge ( ) {
424
- let client = Client :: for_test ( ) . monitor_events ( ) . await ;
425
- if client. is_standalone ( ) {
417
+ if topology_is_standalone ( ) . await {
426
418
log_uncaptured (
427
419
"skipping test_causal_consistency_read_concern_merge due to unsupported topology: \
428
420
standalone",
429
421
) ;
430
422
return ;
431
423
}
432
424
425
+ let client = Client :: for_test ( ) . monitor_events ( ) . await ;
433
426
let mut session = client
434
427
. start_session ( )
435
428
. causal_consistency ( true )
@@ -470,12 +463,12 @@ async fn test_causal_consistency_read_concern_merge() {
470
463
/// Test 11 from the causal consistency specification.
471
464
#[ tokio:: test]
472
465
async fn omit_cluster_time_standalone ( ) {
473
- let client = Client :: for_test ( ) . monitor_events ( ) . await ;
474
- if !client. is_standalone ( ) {
466
+ if !topology_is_standalone ( ) . await {
475
467
log_uncaptured ( "skipping omit_cluster_time_standalone due to unsupported topology" ) ;
476
468
return ;
477
469
}
478
470
471
+ let client = Client :: for_test ( ) . monitor_events ( ) . await ;
479
472
let coll = client
480
473
. database ( "causal_consistency_11" )
481
474
. collection :: < Document > ( "causal_consistency_11" ) ;
@@ -489,15 +482,15 @@ async fn omit_cluster_time_standalone() {
489
482
/// Test 12 from the causal consistency specification.
490
483
#[ tokio:: test]
491
484
async fn cluster_time_sent_in_commands ( ) {
492
- let client = Client :: for_test ( ) . monitor_events ( ) . await ;
493
- if client. is_standalone ( ) {
485
+ if topology_is_standalone ( ) . await {
494
486
log_uncaptured ( "skipping cluster_time_sent_in_commands due to unsupported topology" ) ;
495
487
return ;
496
488
}
497
489
490
+ let client = Client :: for_test ( ) . monitor_events ( ) . await ;
498
491
let coll = client
499
- . database ( "causal_consistency_12" )
500
- . collection :: < Document > ( "causal_consistency_12" ) ;
492
+ . create_fresh_collection ( "causal_consistency_12" , "causal_consistency_12" , None )
493
+ . await ;
501
494
502
495
coll. find_one ( doc ! { } ) . await . unwrap ( ) ;
503
496
0 commit comments