@@ -4726,6 +4726,46 @@ test_bulk_write_set_client_after_operation (void)
4726
4726
mongoc_client_destroy (client );
4727
4727
}
4728
4728
4729
+ // regression test for CDRIVER-5819
4730
+ static void
4731
+ test_bulk_write_set_client_updates_operation_id_when_client_changes (void )
4732
+ {
4733
+ mock_server_t * mock_server ;
4734
+ mongoc_client_t * client , * client2 ;
4735
+ mongoc_bulk_operation_t * bulk ;
4736
+ int64_t last_operation_id ;
4737
+
4738
+ mock_server = mock_server_with_auto_hello (WIRE_VERSION_MIN );
4739
+ mock_server_run (mock_server );
4740
+
4741
+ client = test_framework_client_new_from_uri (mock_server_get_uri (mock_server ), NULL );
4742
+ BSON_ASSERT (client );
4743
+ bulk = mongoc_bulk_operation_new (true /* ordered */ );
4744
+
4745
+ // operation_id is fetched from the client
4746
+ mongoc_bulk_operation_set_client (bulk , client );
4747
+ ASSERT_CMPINT64 (bulk -> operation_id , = = , client -> cluster .operation_id );
4748
+ last_operation_id = bulk -> operation_id ;
4749
+
4750
+ // operation_id is not changed when the client remains the same
4751
+ mongoc_bulk_operation_set_client (bulk , client );
4752
+ ASSERT_CMPINT64 (bulk -> operation_id , = = , last_operation_id );
4753
+ ASSERT_CMPINT64 (bulk -> operation_id , = = , client -> cluster .operation_id );
4754
+
4755
+ // operation_id is updated when the client changes
4756
+ client2 = test_framework_client_new_from_uri (mock_server_get_uri (mock_server ), NULL );
4757
+ BSON_ASSERT (client2 );
4758
+
4759
+ mongoc_bulk_operation_set_client (bulk , client2 );
4760
+ ASSERT_CMPINT64 (bulk -> operation_id , != , last_operation_id );
4761
+ ASSERT_CMPINT64 (bulk -> operation_id , = = , client2 -> cluster .operation_id );
4762
+
4763
+ mongoc_bulk_operation_destroy (bulk );
4764
+ mongoc_client_destroy (client );
4765
+ mongoc_client_destroy (client2 );
4766
+ mock_server_destroy (mock_server );
4767
+ }
4768
+
4729
4769
void
4730
4770
test_bulk_install (TestSuite * suite )
4731
4771
{
@@ -4901,4 +4941,7 @@ test_bulk_install (TestSuite *suite)
4901
4941
/* Require server 4.2 for failCommand appName */
4902
4942
test_framework_skip_if_max_wire_version_less_than_8 );
4903
4943
TestSuite_AddLive (suite , "/BulkOperation/set_client_after_operation" , test_bulk_write_set_client_after_operation );
4944
+ TestSuite_AddMockServerTest (suite ,
4945
+ "/BulkOperation/set_client_updates_operation_id_when_client_changes" ,
4946
+ test_bulk_write_set_client_updates_operation_id_when_client_changes );
4904
4947
}
0 commit comments