Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions src/DtmCommon/Barrier/BranchBarrier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,18 +121,13 @@ public async Task Call(DbConnection db, Func<DbTransaction, Task> busiCall)
}

public async Task Call(DbConnection db, Func<Task> busiCall, TransactionScopeOption transactionScope = TransactionScopeOption.Required, IsolationLevel isolationLevel = IsolationLevel.Serializable)
{
await Call(db, busiCall, transactionScope, isolationLevel, TransactionScopeAsyncFlowOption.Suppress);
}

public async Task Call(DbConnection db, Func<Task> busiCall, TransactionScopeOption transactionScope, IsolationLevel isolationLevel, TransactionScopeAsyncFlowOption transactionScopeAsyncFlowOption)
{
this.BarrierID = this.BarrierID + 1;
var bid = this.BarrierID.ToString().PadLeft(2, '0');

// check the connection state
if (db.State != System.Data.ConnectionState.Open) await db.OpenAsync();
using (var scope = new TransactionScope(transactionScope, new TransactionOptions { IsolationLevel = isolationLevel }, transactionScopeAsyncFlowOption))
using (var scope = new TransactionScope(transactionScope, new TransactionOptions { IsolationLevel = isolationLevel }, TransactionScopeAsyncFlowOption.Enabled))
{
try
{
Expand Down
45 changes: 1 addition & 44 deletions tests/Dtmgrpc.IntegrationTests/MsgGrpcTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,48 +33,6 @@
Assert.Equal("succeed", status);
}

[Fact]
public async Task DoAndSubmit_Should_DbTrans_Exception()
{
var provider = ITTestHelper.AddDtmGrpc();
var transFactory = provider.GetRequiredService<IDtmTransFactory>();

var gid = "msgTestGid" + Guid.NewGuid().ToString();
var msg = transFactory.NewMsgGrpc(gid);
var req = ITTestHelper.GenBusiReq(false, false);
var busiGrpc = ITTestHelper.BuisgRPCUrl;

msg.Add(busiGrpc + "/busi.Busi/TransIn", req);
// 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");
return task;
},
TransactionScopeOption.Required,
IsolationLevel.ReadCommitted
// , default TransactionScopeAsyncFlowOption.Suppress
);
});
});

await Task.Delay(4000);
var status = await ITTestHelper.GetTranStatus(gid);
// The exception did not affect the local transaction commit
Assert.Equal("succeed", status);
}

[Fact]
public async Task DoAndSubmit_Should_Succeed()
{
Expand All @@ -98,8 +56,7 @@
return task;
},
TransactionScopeOption.Required,
IsolationLevel.ReadCommitted,
TransactionScopeAsyncFlowOption.Enabled);
IsolationLevel.ReadCommitted);
});

await Task.Delay(2000);
Expand All @@ -109,7 +66,7 @@

private static readonly int TransOutUID = 1;

private static readonly int TransInUID = 2;

Check warning on line 69 in tests/Dtmgrpc.IntegrationTests/MsgGrpcTest.cs

View workflow job for this annotation

GitHub Actions / build on ubuntu-latest

The field 'MsgGrpcTest.TransInUID' is assigned but its value is never used

Check warning on line 69 in tests/Dtmgrpc.IntegrationTests/MsgGrpcTest.cs

View workflow job for this annotation

GitHub Actions / build on ubuntu-latest

The field 'MsgGrpcTest.TransInUID' is assigned but its value is never used

Check warning on line 69 in tests/Dtmgrpc.IntegrationTests/MsgGrpcTest.cs

View workflow job for this annotation

GitHub Actions / build on ubuntu-latest

The field 'MsgGrpcTest.TransInUID' is assigned but its value is never used

Check warning on line 69 in tests/Dtmgrpc.IntegrationTests/MsgGrpcTest.cs

View workflow job for this annotation

GitHub Actions / build on ubuntu-latest

The field 'MsgGrpcTest.TransInUID' is assigned but its value is never used

Check warning on line 69 in tests/Dtmgrpc.IntegrationTests/MsgGrpcTest.cs

View workflow job for this annotation

GitHub Actions / build on windows-latest

The field 'MsgGrpcTest.TransInUID' is assigned but its value is never used

Check warning on line 69 in tests/Dtmgrpc.IntegrationTests/MsgGrpcTest.cs

View workflow job for this annotation

GitHub Actions / build on windows-latest

The field 'MsgGrpcTest.TransInUID' is assigned but its value is never used

private MySqlConnection getBarrierMySqlConnection() => new("Server=localhost;port=3306;User ID=root;Password=;Database=dtm_barrier");

Expand Down
Loading