@@ -2255,6 +2255,53 @@ assert_event_count (json_test_ctx_t *ctx, const bson_t *operation)
2255
2255
}
2256
2256
}
2257
2257
2258
+ static void
2259
+ assert_session_transaction_state (json_test_ctx_t * ctx , const bson_t * operation )
2260
+ {
2261
+ const char * expected_state ;
2262
+ const mongoc_client_session_t * session ;
2263
+ mongoc_transaction_state_t state ;
2264
+ char * state_strings [] = {
2265
+ "none" , "starting" , "in progress" , "committed" , "aborted" };
2266
+
2267
+ expected_state = bson_lookup_utf8 (operation , "arguments.state" );
2268
+ session = session_from_name (
2269
+ ctx , bson_lookup_utf8 (operation , "arguments.session" ));
2270
+ state = mongoc_client_session_get_transaction_state (session );
2271
+
2272
+ if (!strcmp (expected_state , "none" )) {
2273
+ if (state != MONGOC_TRANSACTION_NONE ) {
2274
+ test_error ("expected session transaction state none, but have %s" ,
2275
+ state_strings [state ]);
2276
+ }
2277
+ } else if (!strcmp (expected_state , "starting" )) {
2278
+ if (state != MONGOC_TRANSACTION_STARTING ) {
2279
+ test_error ("expected session transaction state starting, but have %s" ,
2280
+ state_strings [state ]);
2281
+ }
2282
+ } else if (!strcmp (expected_state , "in_progress" )) {
2283
+ if (state != MONGOC_TRANSACTION_IN_PROGRESS ) {
2284
+ test_error (
2285
+ "expected session transaction state in progress, but have %s" ,
2286
+ state_strings [state ]);
2287
+ }
2288
+ } else if (!strcmp (expected_state , "committed" )) {
2289
+ if (state != MONGOC_TRANSACTION_COMMITTED ) {
2290
+ test_error (
2291
+ "expected session transaction state committed, but have %s" ,
2292
+ state_strings [state ]);
2293
+ }
2294
+ } else if (!strcmp (expected_state , "aborted" )) {
2295
+ if (state != MONGOC_TRANSACTION_ABORTED ) {
2296
+ test_error ("expected session transaction state aborted, but have %s" ,
2297
+ state_strings [state ]);
2298
+ }
2299
+ } else {
2300
+ test_error ("unrecognized state %s for assertSessionTransactionState" ,
2301
+ expected_state );
2302
+ }
2303
+ }
2304
+
2258
2305
static bool
2259
2306
op_error (const bson_t * operation )
2260
2307
{
@@ -2549,6 +2596,8 @@ json_test_operation (json_test_ctx_t *ctx,
2549
2596
wt = thread_from_name (ctx ,
2550
2597
bson_lookup_utf8 (operation , "arguments.name" ));
2551
2598
run_on_thread (wt , & op );
2599
+ } else if (!strcmp (op_name , "assertSessionTransactionState" )) {
2600
+ assert_session_transaction_state (ctx , operation );
2552
2601
} else {
2553
2602
test_error ("unrecognized testRunner operation name %s" , op_name );
2554
2603
}
0 commit comments