From 6e9c29ed87bfe7bcade3a70f2ce246f51a4b1499 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E4=BA=91=E9=87=91YunjinXu?= Date: Fri, 20 Dec 2024 14:54:05 +0800 Subject: [PATCH] test(Dtmgrpc.IntegrationTests): add exception handling and status check in MsgGrpcTest cover Grpc Msg.DoAndSubmit --- tests/Dtmgrpc.IntegrationTests/MsgGrpcTest.cs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/tests/Dtmgrpc.IntegrationTests/MsgGrpcTest.cs b/tests/Dtmgrpc.IntegrationTests/MsgGrpcTest.cs index 2ae06d3..d19ae00 100644 --- a/tests/Dtmgrpc.IntegrationTests/MsgGrpcTest.cs +++ b/tests/Dtmgrpc.IntegrationTests/MsgGrpcTest.cs @@ -48,12 +48,18 @@ public async Task DoAndSubmit_Should_DbTrans_Exception() // do TransOut local, then TransIn with DTM. await Assert.ThrowsAsync(async () => { + // System.InvalidOperationException: A TransactionScope must be disposed on the same thread that it was created. + // + // System.InvalidOperationException + // A TransactionScope must be disposed on the same thread that it was created. + // at Dtmgrpc.MsgGrpc.DoAndSubmit(String queryPrepared, Func`2 busiCall, CancellationToken cancellationToken) in /home/yunjin/Data/projects/github/dtm-labs/client-csharp/src/Dtmgrpc/Msg/MsgGrpc.cs:line 110 + await msg.DoAndSubmit(busiGrpc + "/busi.Busi/QueryPreparedMySqlReal", async branchBarrier => { MySqlConnection conn = getBarrierMySqlConnection(); await branchBarrier.Call(conn, () => { - Task task = this.LocalAdjustBalance(conn, TransOutUID, req.Amount, "SUCCESS"); + Task task = this.LocalAdjustBalance(conn, TransOutUID, -req.Amount, "SUCCESS"); return task; }, TransactionScopeOption.Required, @@ -62,6 +68,11 @@ await branchBarrier.Call(conn, () => ); }); }); + + await Task.Delay(4000); + var status = await ITTestHelper.GetTranStatus(gid); + // The exception did not affect the local transaction commit + Assert.Equal("succeed", status); } [Fact] @@ -83,7 +94,7 @@ await msg.DoAndSubmit(busiGrpc + "/busi.Busi/QueryPreparedMySqlReal", async bran MySqlConnection conn = getBarrierMySqlConnection(); await branchBarrier.Call(conn, () => { - Task task = this.LocalAdjustBalance(conn, TransOutUID, req.Amount, "SUCCESS"); + Task task = this.LocalAdjustBalance(conn, TransOutUID, -req.Amount, "SUCCESS"); return task; }, TransactionScopeOption.Required,