@@ -458,6 +458,72 @@ test_split_opquery_with_options (void)
458
458
mock_server_destroy (server );
459
459
}
460
460
461
+ static void
462
+ test_opmsg_disconnect_mid_batch_helper (int wire_version )
463
+ {
464
+ mock_server_t * server ;
465
+ mongoc_client_t * client ;
466
+ mongoc_collection_t * coll ;
467
+ bson_t * * docs ;
468
+ int i ;
469
+ bson_error_t error ;
470
+ future_t * future ;
471
+ request_t * request ;
472
+ int n_docs ;
473
+
474
+ /* Use a reduced maxBsonObjectSize, and wire version for OP_QUERY */
475
+ const char * ismaster = "{'ok': 1.0,"
476
+ " 'ismaster': true,"
477
+ " 'minWireVersion': 0,"
478
+ " 'maxWireVersion': %d,"
479
+ " 'maxBsonObjectSize': 100}" ;
480
+
481
+ server = mock_server_new ();
482
+ mock_server_auto_ismaster (server , ismaster , wire_version );
483
+ mock_server_run (server );
484
+
485
+ /* create enough documents for two batches. Note, because of our wonky
486
+ * batch splitting behavior (to be fixed in CDRIVER-3310) we need add 16K
487
+ * of documents. After CDRIVER-3310, we'll need to update this test. */
488
+ n_docs = ((BSON_OBJECT_ALLOWANCE ) / tmp_bson ("{ '_id': 1 }" )-> len ) + 1 ;
489
+ docs = bson_malloc (sizeof (bson_t * ) * n_docs );
490
+ for (i = 0 ; i < n_docs ; i ++ ) {
491
+ docs [i ] = BCON_NEW ("_id" , BCON_INT64 (i ));
492
+ }
493
+
494
+ client = mongoc_client_new_from_uri (mock_server_get_uri (server ));
495
+ mongoc_client_set_error_api (client , MONGOC_ERROR_API_VERSION_2 );
496
+ coll = mongoc_client_get_collection (client , "db" , "coll" );
497
+
498
+ future = future_collection_insert_many (
499
+ coll , (const bson_t * * ) docs , n_docs , NULL , NULL , & error );
500
+ /* Mock server recieves first insert. */
501
+ request = mock_server_receives_request (server );
502
+ BSON_ASSERT (request );
503
+ mock_server_hangs_up (request );
504
+ request_destroy (request );
505
+
506
+ BSON_ASSERT (!future_get_bool (future ));
507
+ future_destroy (future );
508
+ ASSERT_ERROR_CONTAINS (
509
+ error , MONGOC_ERROR_STREAM , MONGOC_ERROR_STREAM_SOCKET , "socket error" );
510
+
511
+ for (i = 0 ; i < n_docs ; i ++ ) {
512
+ bson_destroy (docs [i ]);
513
+ }
514
+ bson_free (docs );
515
+ mongoc_collection_destroy (coll );
516
+ mongoc_client_destroy (client );
517
+ mock_server_destroy (server );
518
+ }
519
+
520
+ static void
521
+ test_opmsg_disconnect_mid_batch (void )
522
+ {
523
+ test_opmsg_disconnect_mid_batch_helper (WIRE_VERSION_OP_MSG );
524
+ test_opmsg_disconnect_mid_batch_helper (WIRE_VERSION_OP_MSG - 1 );
525
+ }
526
+
461
527
void
462
528
test_write_command_install (TestSuite * suite )
463
529
{
@@ -475,4 +541,7 @@ test_write_command_install (TestSuite *suite)
475
541
TestSuite_AddMockServerTest (suite ,
476
542
"/WriteCommand/split_opquery_with_options" ,
477
543
test_split_opquery_with_options );
544
+ TestSuite_AddMockServerTest (suite ,
545
+ "/WriteCommand/insert_disconnect_mid_batch" ,
546
+ test_opmsg_disconnect_mid_batch );
478
547
}
0 commit comments