@@ -2568,6 +2568,177 @@ test_aggregate_install (TestSuite *suite) {
2568
2568
}
2569
2569
2570
2570
2571
+ static void
2572
+ test_find_read_concern (void )
2573
+ {
2574
+ mock_server_t * server ;
2575
+ mongoc_client_t * client ;
2576
+ mongoc_read_concern_t * rc ;
2577
+ mongoc_collection_t * collection ;
2578
+ mongoc_cursor_t * cursor ;
2579
+ future_t * future ;
2580
+ request_t * request ;
2581
+ const bson_t * doc ;
2582
+
2583
+ server = mock_server_with_autoismaster (WIRE_VERSION_READ_CONCERN );
2584
+ mock_server_run (server );
2585
+
2586
+ client = mongoc_client_new_from_uri (mock_server_get_uri (server ));
2587
+ collection = mongoc_client_get_collection (client , "test" , "test" );
2588
+
2589
+ /* No read_concern set */
2590
+ cursor = mongoc_collection_find (collection ,
2591
+ MONGOC_QUERY_SLAVE_OK ,
2592
+ 0 /* skip */ ,
2593
+ 0 /* limit */ ,
2594
+ 0 /* batch_size */ ,
2595
+ tmp_bson ("{}" ),
2596
+ NULL ,
2597
+ NULL );
2598
+
2599
+ future = future_cursor_next (cursor , & doc );
2600
+ request = mock_server_receives_command (server , "test" , MONGOC_QUERY_SLAVE_OK ,
2601
+ "{'find' : 'test', 'filter' : { } }" );
2602
+ mock_server_replies_simple (request , "{'ok': 1,"
2603
+ " 'cursor': {"
2604
+ " 'id': 0,"
2605
+ " 'ns': 'test.test',"
2606
+ " 'firstBatch': [{'_id': 123}]}}" );
2607
+ ASSERT (future_get_bool (future ));
2608
+ future_destroy (future );
2609
+ request_destroy (request );
2610
+ mongoc_cursor_destroy (cursor );
2611
+
2612
+ /* readConcernLevel = local */
2613
+ rc = mongoc_read_concern_new ();
2614
+ mongoc_read_concern_set_level (rc , MONGOC_READ_CONCERN_LEVEL_LOCAL );
2615
+ mongoc_collection_set_read_concern (collection , rc );
2616
+ cursor = mongoc_collection_find (collection ,
2617
+ MONGOC_QUERY_SLAVE_OK ,
2618
+ 0 /* skip */ ,
2619
+ 0 /* limit */ ,
2620
+ 0 /* batch_size */ ,
2621
+ tmp_bson ("{}" ),
2622
+ NULL ,
2623
+ NULL );
2624
+
2625
+ future = future_cursor_next (cursor , & doc );
2626
+ request = mock_server_receives_command (server , "test" , MONGOC_QUERY_SLAVE_OK ,
2627
+ "{"
2628
+ " 'find' : 'test',"
2629
+ " 'filter' : { },"
2630
+ " 'readConcern': {"
2631
+ " 'level': 'local'"
2632
+ " }"
2633
+ "}" );
2634
+ mock_server_replies_simple (request , "{'ok': 1,"
2635
+ " 'cursor': {"
2636
+ " 'id': 0,"
2637
+ " 'ns': 'test.test',"
2638
+ " 'firstBatch': [{'_id': 123}]}}" );
2639
+ ASSERT (future_get_bool (future ));
2640
+ future_destroy (future );
2641
+ request_destroy (request );
2642
+ mongoc_cursor_destroy (cursor );
2643
+
2644
+ /* readConcernLevel = random */
2645
+ rc = mongoc_read_concern_new ();
2646
+ mongoc_read_concern_set_level (rc , "random" );
2647
+ mongoc_collection_set_read_concern (collection , rc );
2648
+ cursor = mongoc_collection_find (collection ,
2649
+ MONGOC_QUERY_SLAVE_OK ,
2650
+ 0 /* skip */ ,
2651
+ 0 /* limit */ ,
2652
+ 0 /* batch_size */ ,
2653
+ tmp_bson ("{}" ),
2654
+ NULL ,
2655
+ NULL );
2656
+
2657
+ future = future_cursor_next (cursor , & doc );
2658
+ request = mock_server_receives_command (server , "test" , MONGOC_QUERY_SLAVE_OK ,
2659
+ "{"
2660
+ " 'find' : 'test',"
2661
+ " 'filter' : { },"
2662
+ " 'readConcern': {"
2663
+ " 'level': 'random'"
2664
+ " }"
2665
+ "}" );
2666
+ mock_server_replies_simple (request , "{'ok': 1,"
2667
+ " 'cursor': {"
2668
+ " 'id': 0,"
2669
+ " 'ns': 'test.test',"
2670
+ " 'firstBatch': [{'_id': 123}]}}" );
2671
+ ASSERT (future_get_bool (future ));
2672
+ future_destroy (future );
2673
+ request_destroy (request );
2674
+ mongoc_cursor_destroy (cursor );
2675
+
2676
+ /* empty readConcernLevel doesn't send anything */
2677
+ rc = mongoc_read_concern_new ();
2678
+ mongoc_collection_set_read_concern (collection , rc );
2679
+ cursor = mongoc_collection_find (collection ,
2680
+ MONGOC_QUERY_SLAVE_OK ,
2681
+ 0 /* skip */ ,
2682
+ 0 /* limit */ ,
2683
+ 0 /* batch_size */ ,
2684
+ tmp_bson ("{}" ),
2685
+ NULL ,
2686
+ NULL );
2687
+
2688
+ future = future_cursor_next (cursor , & doc );
2689
+ request = mock_server_receives_command (server , "test" , MONGOC_QUERY_SLAVE_OK ,
2690
+ "{"
2691
+ " 'find' : 'test',"
2692
+ " 'filter' : { },"
2693
+ " 'readConcern': { '$exists': false }"
2694
+ "}" );
2695
+ mock_server_replies_simple (request , "{'ok': 1,"
2696
+ " 'cursor': {"
2697
+ " 'id': 0,"
2698
+ " 'ns': 'test.test',"
2699
+ " 'firstBatch': [{'_id': 123}]}}" );
2700
+ ASSERT (future_get_bool (future ));
2701
+ future_destroy (future );
2702
+ request_destroy (request );
2703
+ mongoc_cursor_destroy (cursor );
2704
+
2705
+ /* readConcernLevel = NULL doesn't send anything */
2706
+ rc = mongoc_read_concern_new ();
2707
+ mongoc_read_concern_set_level (rc , NULL );
2708
+ mongoc_collection_set_read_concern (collection , rc );
2709
+ cursor = mongoc_collection_find (collection ,
2710
+ MONGOC_QUERY_SLAVE_OK ,
2711
+ 0 /* skip */ ,
2712
+ 0 /* limit */ ,
2713
+ 0 /* batch_size */ ,
2714
+ tmp_bson ("{}" ),
2715
+ NULL ,
2716
+ NULL );
2717
+
2718
+ future = future_cursor_next (cursor , & doc );
2719
+ request = mock_server_receives_command (server , "test" , MONGOC_QUERY_SLAVE_OK ,
2720
+ "{"
2721
+ " 'find' : 'test',"
2722
+ " 'filter' : { },"
2723
+ " 'readConcern': { '$exists': false }"
2724
+ "}" );
2725
+ mock_server_replies_simple (request , "{'ok': 1,"
2726
+ " 'cursor': {"
2727
+ " 'id': 0,"
2728
+ " 'ns': 'test.test',"
2729
+ " 'firstBatch': [{'_id': 123}]}}" );
2730
+ ASSERT (future_get_bool (future ));
2731
+ future_destroy (future );
2732
+ request_destroy (request );
2733
+ mongoc_cursor_destroy (cursor );
2734
+
2735
+ mongoc_collection_destroy (collection );
2736
+ mongoc_client_destroy (client );
2737
+ mock_server_destroy (server );
2738
+ }
2739
+
2740
+
2741
+
2571
2742
void
2572
2743
test_collection_install (TestSuite * suite )
2573
2744
{
@@ -2620,6 +2791,7 @@ test_collection_install (TestSuite *suite)
2620
2791
TestSuite_Add (suite , "/Collection/validate" , test_validate );
2621
2792
TestSuite_Add (suite , "/Collection/rename" , test_rename );
2622
2793
TestSuite_Add (suite , "/Collection/stats" , test_stats );
2794
+ TestSuite_Add (suite , "/Collection/find_read_concern" , test_find_read_concern );
2623
2795
TestSuite_Add (suite , "/Collection/find_and_modify" , test_find_and_modify );
2624
2796
TestSuite_Add (suite , "/Collection/find_and_modify/write_concern" ,
2625
2797
test_find_and_modify_write_concern_wire_32 );
0 commit comments