@@ -2738,6 +2738,113 @@ test_find_read_concern (void)
2738
2738
}
2739
2739
2740
2740
2741
+ static void
2742
+ test_aggregate_read_concern (void )
2743
+ {
2744
+ mock_server_t * server ;
2745
+ mongoc_client_t * client ;
2746
+ mongoc_collection_t * collection ;
2747
+ mongoc_read_concern_t * rc ;
2748
+ future_t * future ;
2749
+ request_t * request ;
2750
+ mongoc_cursor_t * cursor ;
2751
+ const bson_t * doc ;
2752
+
2753
+ server = mock_server_with_autoismaster (WIRE_VERSION_READ_CONCERN );
2754
+ mock_server_run (server );
2755
+ client = mongoc_client_new_from_uri (mock_server_get_uri (server ));
2756
+ collection = mongoc_client_get_collection (client , "db" , "collection" );
2757
+
2758
+ /* No readConcern */
2759
+ cursor = mongoc_collection_aggregate (
2760
+ collection ,
2761
+ MONGOC_QUERY_NONE ,
2762
+ tmp_bson ("[{'a': 1}]" ),
2763
+ NULL ,
2764
+ NULL );
2765
+
2766
+ ASSERT (cursor );
2767
+ future = future_cursor_next (cursor , & doc );
2768
+
2769
+ request = mock_server_receives_command (
2770
+ server , "db" , MONGOC_QUERY_SLAVE_OK ,
2771
+ "{"
2772
+ " 'aggregate' : 'collection',"
2773
+ " 'pipeline' : [{"
2774
+ " 'a' : 1"
2775
+ " }],"
2776
+ " 'cursor' : { },"
2777
+ " 'readConcern': { '$exists': false }"
2778
+ "}"
2779
+ );
2780
+
2781
+ mock_server_replies_simple (request ,
2782
+ "{'ok': 1,"
2783
+ " 'cursor': {"
2784
+ " 'id': 0,"
2785
+ " 'ns': 'db.collection',"
2786
+ " 'firstBatch': [{'_id': 123}]"
2787
+ "}}" );
2788
+
2789
+ ASSERT (future_get_bool (future ));
2790
+ ASSERT_MATCH (doc , "{'_id': 123}" );
2791
+
2792
+ /* cursor is completed */
2793
+ assert (!mongoc_cursor_next (cursor , & doc ));
2794
+ mongoc_cursor_destroy (cursor );
2795
+ request_destroy (request );
2796
+ future_destroy (future );
2797
+
2798
+ /* readConcern: majority */
2799
+ rc = mongoc_read_concern_new ();
2800
+ mongoc_read_concern_set_level (rc , MONGOC_READ_CONCERN_LEVEL_MAJORITY );
2801
+ mongoc_collection_set_read_concern (collection , rc );
2802
+ cursor = mongoc_collection_aggregate (
2803
+ collection ,
2804
+ MONGOC_QUERY_NONE ,
2805
+ tmp_bson ("[{'a': 1}]" ),
2806
+ NULL ,
2807
+ NULL );
2808
+
2809
+ ASSERT (cursor );
2810
+ future = future_cursor_next (cursor , & doc );
2811
+
2812
+ request = mock_server_receives_command (
2813
+ server , "db" , MONGOC_QUERY_SLAVE_OK ,
2814
+ "{"
2815
+ " 'aggregate' : 'collection',"
2816
+ " 'pipeline' : [{"
2817
+ " 'a' : 1"
2818
+ " }],"
2819
+ " 'cursor' : { },"
2820
+ " 'readConcern': { 'level': 'majority'}"
2821
+ "}"
2822
+ );
2823
+
2824
+ mock_server_replies_simple (request ,
2825
+ "{'ok': 1,"
2826
+ " 'cursor': {"
2827
+ " 'id': 0,"
2828
+ " 'ns': 'db.collection',"
2829
+ " 'firstBatch': [{'_id': 123}]"
2830
+ "}}" );
2831
+
2832
+ ASSERT (future_get_bool (future ));
2833
+ ASSERT_MATCH (doc , "{'_id': 123}" );
2834
+
2835
+ /* cursor is completed */
2836
+ assert (!mongoc_cursor_next (cursor , & doc ));
2837
+ mongoc_cursor_destroy (cursor );
2838
+ request_destroy (request );
2839
+ future_destroy (future );
2840
+
2841
+
2842
+ mongoc_collection_destroy (collection );
2843
+ mongoc_client_destroy (client );
2844
+ mock_server_destroy (server );
2845
+ }
2846
+
2847
+
2741
2848
2742
2849
void
2743
2850
test_collection_install (TestSuite * suite )
@@ -2787,6 +2894,7 @@ test_collection_install (TestSuite *suite)
2787
2894
TestSuite_Add (suite , "/Collection/drop" , test_drop );
2788
2895
TestSuite_Add (suite , "/Collection/aggregate" , test_aggregate );
2789
2896
TestSuite_Add (suite , "/Collection/aggregate/large" , test_aggregate_large );
2897
+ TestSuite_Add (suite , "/Collection/aggregate/read_concern" , test_aggregate_read_concern );
2790
2898
TestSuite_AddFull (suite , "/Collection/aggregate/bypass_document_validation" , test_aggregate_bypass , NULL , NULL , test_framework_skip_if_max_version_version_less_than_4 );
2791
2899
TestSuite_Add (suite , "/Collection/validate" , test_validate );
2792
2900
TestSuite_Add (suite , "/Collection/rename" , test_rename );
0 commit comments