@@ -968,6 +968,62 @@ test_selected_server_is_pinned_to_mongos (void *ctx)
968
968
mongoc_uri_destroy (uri );
969
969
}
970
970
971
+ static void
972
+ test_max_commit_time_ms_is_reset (void * ctx )
973
+ {
974
+ mock_rs_t * rs ;
975
+ mongoc_uri_t * uri = NULL ;
976
+ mongoc_client_t * client = NULL ;
977
+ mongoc_transaction_opt_t * txn_opts = NULL ;
978
+ mongoc_session_opt_t * session_opts = NULL ;
979
+ mongoc_client_session_t * session = NULL ;
980
+ bson_error_t error ;
981
+ bool r ;
982
+
983
+ rs = mock_rs_with_autoismaster (WIRE_VERSION_4_2 ,
984
+ true /* has primary */ ,
985
+ 2 /* secondaries */ ,
986
+ 0 /* arbiters */ );
987
+
988
+ mock_rs_run (rs );
989
+ uri = mongoc_uri_copy (mock_rs_get_uri (rs ));
990
+
991
+ client = mongoc_client_new_from_uri (uri );
992
+ BSON_ASSERT (client );
993
+
994
+ txn_opts = mongoc_transaction_opts_new ();
995
+ session_opts = mongoc_session_opts_new ();
996
+
997
+ session = mongoc_client_start_session (client , session_opts , & error );
998
+ ASSERT_OR_PRINT (session , error );
999
+
1000
+ mongoc_transaction_opts_set_max_commit_time_ms (txn_opts , 1 );
1001
+
1002
+ r = mongoc_client_session_start_transaction (session , txn_opts , & error );
1003
+ ASSERT_OR_PRINT (r , error );
1004
+ BSON_ASSERT (1 == session -> txn .opts .max_commit_time_ms );
1005
+
1006
+ r = mongoc_client_session_abort_transaction (session , & error );
1007
+ ASSERT_OR_PRINT (r , error );
1008
+ BSON_ASSERT (DEFAULT_MAX_COMMIT_TIME_MS == session -> txn .opts .max_commit_time_ms );
1009
+
1010
+ mongoc_transaction_opts_set_max_commit_time_ms (txn_opts , DEFAULT_MAX_COMMIT_TIME_MS );
1011
+
1012
+ r = mongoc_client_session_start_transaction (session , txn_opts , & error );
1013
+ ASSERT_OR_PRINT (r , error );
1014
+ BSON_ASSERT (DEFAULT_MAX_COMMIT_TIME_MS == session -> txn .opts .max_commit_time_ms );
1015
+
1016
+ r = mongoc_client_session_abort_transaction (session , & error );
1017
+ ASSERT_OR_PRINT (r , error );
1018
+
1019
+ mongoc_session_opts_destroy (session_opts );
1020
+ mongoc_transaction_opts_destroy (txn_opts );
1021
+ mongoc_client_session_destroy (session );
1022
+ mongoc_client_destroy (client );
1023
+ mongoc_uri_destroy (uri );
1024
+ mock_rs_destroy (rs );
1025
+ }
1026
+
971
1027
void
972
1028
test_transactions_install (TestSuite * suite )
973
1029
{
@@ -1043,4 +1099,10 @@ test_transactions_install (TestSuite *suite)
1043
1099
test_framework_skip_if_no_sessions ,
1044
1100
test_framework_skip_if_max_wire_version_less_than_8 ,
1045
1101
test_framework_skip_if_not_mongos );
1102
+ TestSuite_AddFull (suite ,
1103
+ "/transactions/max_commit_time_ms_is_reset" ,
1104
+ test_max_commit_time_ms_is_reset ,
1105
+ NULL ,
1106
+ NULL ,
1107
+ NULL );
1046
1108
}
0 commit comments