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
10 changes: 10 additions & 0 deletions src/Dtmcli/Msg/Msg.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,16 @@ public Msg SetDelay(long delay)
this._delay = delay;
return this;
}

/// <summary>
/// Set delay to call branch
/// </summary>
/// <returns></returns>
public Msg SetDelay(TimeSpan delay)
{
this._delay = (long)delay.TotalSeconds;
return this;
}

private void BuildCustomOptions()
{
Expand Down
10 changes: 10 additions & 0 deletions src/Dtmgrpc/Msg/MsgGrpc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,16 @@ public MsgGrpc SetDelay(long delay)
this._delay = delay;
return this;
}

/// <summary>
/// Set delay to call branch, unit second
/// </summary>
/// <returns></returns>
public MsgGrpc SetDelay(TimeSpan delay)
{
this._delay = (long)delay.TotalSeconds;
return this;
}

private void BuildCustomOptions()
{
Expand Down
32 changes: 32 additions & 0 deletions tests/Dtmcli.IntegrationTests/MsgHttpTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,36 @@ public async Task Submit_With_EffectTime_Should_Succeed_Later()
status = await ITTestHelper.GetTranStatus(gid);
Assert.Equal("succeed", status);
}

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

var gid = "msgTestGid" + Guid.NewGuid().ToString();
Msg msg = transFactory.NewMsg(gid);
msg.SetDelay(TimeSpan.FromSeconds(10));

var req = ITTestHelper.GenBusiReq(false, false);
var busiUrl = ITTestHelper.BuisHttpUrl;
msg.Add(busiUrl + "/busi.Busi/TransOut", req)
.Add(busiUrl + "/busi.Busi/TransIn", req);

await msg.Prepare(busiUrl + "/busi.Busi/QueryPrepared_404");
await msg.Submit();

// Since the downstream execution is delayed by 10 seconds, it will be 'submitted' after 2 seconds and 'succeed' after 15 seconds
await Task.Delay(TimeSpan.FromSeconds(0));
var status = await ITTestHelper.GetTranStatus(gid);
Assert.Equal("submitted", status);

await Task.Delay(TimeSpan.FromSeconds(2));
status = await ITTestHelper.GetTranStatus(gid);
Assert.Equal("submitted", status);

await Task.Delay(TimeSpan.FromSeconds(13));
status = await ITTestHelper.GetTranStatus(gid);
Assert.Equal("succeed", status);
}
}
26 changes: 26 additions & 0 deletions tests/Dtmgrpc.IntegrationTests/MsgGrpcTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,36 @@
Assert.Equal("succeed", status);
}

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

var gid = "msgTestGid" + Guid.NewGuid().ToString();
var msg = transFactory.NewMsgGrpc(gid);
msg.SetDelay(TimeSpan.FromSeconds(10));
var req = ITTestHelper.GenBusiReq(false, false);
var busiGrpc = ITTestHelper.BuisgRPCUrl;
msg.Add(busiGrpc + "/busi.Busi/TransOut", req)
.Add(busiGrpc + "/busi.Busi/TransIn", req);

await msg.Prepare(busiGrpc + "/busi.Busi/QueryPrepared");
await msg.Submit();

// Since the downstream execution is delayed by 10 seconds, it will be 'submitted' after 2 seconds and 'succeed' after 15 seconds
await Task.Delay(TimeSpan.FromSeconds(2));
var status = await ITTestHelper.GetTranStatus(gid);
Assert.Equal("submitted", status);

await Task.Delay(TimeSpan.FromSeconds(13));
status = await ITTestHelper.GetTranStatus(gid);
Assert.Equal("succeed", status);
}

private static readonly int TransOutUID = 1;

private static readonly int TransInUID = 2;

Check warning on line 124 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 124 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 124 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 124 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 124 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 124 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

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

Expand Down
Loading