Skip to content

Commit

Permalink
test(Dtmgrpc.IntegrationTests): add exception handling and status che…
Browse files Browse the repository at this point in the history
…ck in MsgGrpcTest

cover Grpc Msg.DoAndSubmit
  • Loading branch information
wooln committed Dec 20, 2024
1 parent e713bf5 commit 6e9c29e
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions tests/Dtmgrpc.IntegrationTests/MsgGrpcTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,18 @@ public async Task DoAndSubmit_Should_DbTrans_Exception()
// do TransOut local, then TransIn with DTM.
await Assert.ThrowsAsync<System.InvalidOperationException>(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,
Expand All @@ -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]
Expand All @@ -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,
Expand Down

0 comments on commit 6e9c29e

Please sign in to comment.