@@ -629,6 +629,58 @@ test_bulkwrite_execute_requires_client (void *ctx)
629
629
mongoc_client_destroy (client );
630
630
}
631
631
632
+ // `test_bulkwrite_two_large_inserts` is a regression test for CDRIVER-5869.
633
+ static void
634
+ test_bulkwrite_two_large_inserts (void * unused )
635
+ {
636
+ BSON_UNUSED (unused );
637
+
638
+ bson_error_t error ;
639
+ mongoc_client_t * client = test_framework_new_default_client ();
640
+
641
+ // Drop prior collection:
642
+ {
643
+ mongoc_collection_t * coll = mongoc_client_get_collection (client , "db" , "coll" );
644
+ mongoc_collection_drop (coll , NULL );
645
+ mongoc_collection_destroy (coll );
646
+ }
647
+
648
+ // Allocate a large string:
649
+ size_t large_len = 2095652 ;
650
+ char * large_string = bson_malloc (large_len + 1 );
651
+ memset (large_string , 'a' , large_len );
652
+ large_string [large_len ] = '\0' ;
653
+
654
+ // Create two large documents:
655
+ bson_t * docs [2 ];
656
+ docs [0 ] = BCON_NEW ("_id" , "over_2mib_1" );
657
+ bson_append_utf8 (docs [0 ], "unencrypted" , -1 , large_string , large_len );
658
+ docs [1 ] = BCON_NEW ("_id" , "over_2mib_2" );
659
+ bson_append_utf8 (docs [1 ], "unencrypted" , -1 , large_string , large_len );
660
+
661
+ mongoc_bulkwriteopts_t * bw_opts = mongoc_bulkwriteopts_new ();
662
+ mongoc_bulkwriteopts_set_verboseresults (bw_opts , true);
663
+
664
+ mongoc_bulkwrite_t * bw = mongoc_client_bulkwrite_new (client );
665
+ ASSERT_OR_PRINT (mongoc_bulkwrite_append_insertone (bw , "db.coll" , docs [0 ], NULL , & error ), error );
666
+ ASSERT_OR_PRINT (mongoc_bulkwrite_append_insertone (bw , "db.coll" , docs [1 ], NULL , & error ), error );
667
+
668
+ mongoc_bulkwritereturn_t bwr = mongoc_bulkwrite_execute (bw , bw_opts ); // Crashes!
669
+ ASSERT_NO_BULKWRITEEXCEPTION (bwr );
670
+ ASSERT (bwr .res );
671
+ const bson_t * insertresults = mongoc_bulkwriteresult_insertresults (bwr .res );
672
+ ASSERT_MATCH (insertresults ,
673
+ BSON_STR ({"0" : {"insertedId" : "over_2mib_1 "}}, {" 1 " : {" insertedId " : " over_2mib_2 "}}));
674
+ bson_destroy (docs [0 ]);
675
+ bson_destroy (docs [1 ]);
676
+ mongoc_bulkwrite_destroy (bw );
677
+ mongoc_bulkwriteresult_destroy (bwr .res );
678
+ mongoc_bulkwriteexception_destroy (bwr .exc );
679
+ mongoc_bulkwriteopts_destroy (bw_opts );
680
+ mongoc_client_destroy (client );
681
+ bson_free (large_string );
682
+ }
683
+
632
684
void
633
685
test_bulkwrite_install (TestSuite * suite )
634
686
{
@@ -722,4 +774,12 @@ test_bulkwrite_install (TestSuite *suite)
722
774
NULL /* ctx */ ,
723
775
test_framework_skip_if_max_wire_version_less_than_25 // require server 8.0
724
776
);
777
+
778
+ TestSuite_AddFull (suite ,
779
+ "/bulkwrite/two_large_inserts" ,
780
+ test_bulkwrite_two_large_inserts ,
781
+ NULL /* dtor */ ,
782
+ NULL /* ctx */ ,
783
+ test_framework_skip_if_max_wire_version_less_than_25 // require server 8.0
784
+ );
725
785
}
0 commit comments