@@ -876,8 +876,65 @@ test_replace_one (bool ordered)
876
876
}
877
877
878
878
879
+ /*
880
+ * check that we include command overhead in msg size when deciding to split,
881
+ * CDRIVER-1082
882
+ */
879
883
static void
880
884
test_upsert_large (void )
885
+ {
886
+ mongoc_bulk_operation_t * bulk ;
887
+ mongoc_collection_t * collection ;
888
+ mongoc_client_t * client ;
889
+ bool has_write_cmds ;
890
+ bson_t * selector = tmp_bson ("{'_id': 'aaaaaaaaaa'}" );
891
+ size_t sz = 8396691 ; /* a little over 8 MB */
892
+ char * large_str = bson_malloc (sz );
893
+ bson_t update = BSON_INITIALIZER ;
894
+ bson_t child ;
895
+ bson_error_t error ;
896
+ int i ;
897
+ bson_t reply ;
898
+
899
+ client = test_framework_client_new ();
900
+ has_write_cmds = server_has_write_commands (client );
901
+ collection = get_test_collection (client , "test_upsert_large" );
902
+ bulk = mongoc_collection_create_bulk_operation (collection , true, NULL );
903
+
904
+ bson_append_document_begin (& update , "$set" , 4 , & child );
905
+ bson_append_utf8 (& child , "big" , 3 , large_str , (int ) sz );
906
+ bson_append_document_end (& update , & child );
907
+
908
+ /* two 8MB+ docs could fit in 16MB + 16K, if not for command overhead,
909
+ * check the driver splits into two msgs */
910
+ for (i = 0 ; i < 2 ; i ++ ) {
911
+ mongoc_bulk_operation_update (bulk , selector , & update , true);
912
+ }
913
+
914
+ ASSERT_OR_PRINT ((bool ) mongoc_bulk_operation_execute (bulk , & reply , & error ),
915
+ error );
916
+
917
+ ASSERT_MATCH (& reply , "{'nInserted': 0,"
918
+ " 'nMatched': 1,"
919
+ " 'nRemoved': 0,"
920
+ " 'nUpserted': 1,"
921
+ " 'upserted': [{'index': 0, '_id': 'aaaaaaaaaa'}],"
922
+ " 'writeErrors': []}" );
923
+
924
+ check_n_modified (has_write_cmds , & reply , 0 );
925
+ ASSERT_COUNT (1 , collection );
926
+
927
+ bson_destroy (& reply );
928
+ mongoc_bulk_operation_destroy (bulk );
929
+ mongoc_collection_destroy (collection );
930
+ mongoc_client_destroy (client );
931
+ bson_destroy (& update );
932
+ bson_free (large_str );
933
+ }
934
+
935
+
936
+ static void
937
+ test_upsert_huge (void )
881
938
{
882
939
mongoc_bulk_operation_t * bulk ;
883
940
mongoc_collection_t * collection ;
@@ -897,7 +954,7 @@ test_upsert_large (void)
897
954
assert (client );
898
955
has_write_cmds = server_has_write_commands (client );
899
956
900
- collection = get_test_collection (client , "test_upsert_large " );
957
+ collection = get_test_collection (client , "test_upsert_huge " );
901
958
assert (collection );
902
959
903
960
bulk = mongoc_collection_create_bulk_operation (collection , true, NULL );
@@ -2852,6 +2909,8 @@ test_bulk_install (TestSuite *suite)
2852
2909
test_upsert_unordered );
2853
2910
TestSuite_Add (suite , "/BulkOperation/upsert_large" ,
2854
2911
test_upsert_large );
2912
+ TestSuite_Add (suite , "/BulkOperation/upsert_huge" ,
2913
+ test_upsert_huge );
2855
2914
TestSuite_Add (suite , "/BulkOperation/upserted_index_ordered" ,
2856
2915
test_upserted_index_ordered );
2857
2916
TestSuite_Add (suite , "/BulkOperation/upserted_index_unordered" ,
0 commit comments