Skip to content

Commit 16f174d

Browse files
authored
Bugfix workflow execute dtmfailureexception (#100)
* Change the test method to verify exception handling  Change the test method name to a more accurate description, and update the test logic to expect a 'DtmFailureException' instead of returning 'null'. This enhances the verification of exception handling. * Inside the 'Process' method, a check for the 'err' variable is added to make sure an error is thrown if 'err' is not null. Modify the exception assertion of the 'Rollback_Should_Be_Executed' single test to use 'Assert.ThrowsAsync' to verify whether a 'DtmFailureException' was thrown.
1 parent 8c65784 commit 16f174d

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/Dtmworkflow/Workflow.Imp.cs

+3
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ internal async Task<byte[]> Process(WfFunc2 handler, byte[] data)
8181
await this.Submit(res, err, default);
8282
}
8383

84+
if (err != null)
85+
throw err;
86+
8487
return res;
8588
}
8689

tests/Dtmworkflow.Tests/WorkflowHttpTests.cs

+4-5
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public async void Execute_Should_ThrowException_When_WfFunc2_ThrowException()
141141
}
142142

143143
[Fact]
144-
public async void Execute_Should_Return_Null_When_WfFunc2_ThrowDtmFailureException()
144+
public async void Execute_Should_ThrowDtmFailureException_When_WfFunc2_ThrowDtmFailureException()
145145
{
146146
var factory = new Mock<IWorkflowFactory>();
147147
var httpClient = new Mock<IDtmClient>();
@@ -161,7 +161,7 @@ public async void Execute_Should_Return_Null_When_WfFunc2_ThrowDtmFailureExcepti
161161

162162
var wfgt = new WorkflowGlobalTransaction(factory.Object, NullLoggerFactory.Instance);
163163

164-
var wfName = nameof(Execute_Should_Return_Null_When_WfFunc2_ThrowDtmFailureException);
164+
var wfName = nameof(Execute_Should_ThrowDtmFailureException_When_WfFunc2_ThrowDtmFailureException);
165165
var gid = Guid.NewGuid().ToString("N");
166166

167167
var handler = new Mock<WfFunc2>();
@@ -170,8 +170,7 @@ public async void Execute_Should_Return_Null_When_WfFunc2_ThrowDtmFailureExcepti
170170
wfgt.Register(wfName, handler.Object);
171171
var req = JsonSerializer.Serialize(new { userId = "1", amount = 30 });
172172

173-
var res = await wfgt.Execute(wfName, gid, Encoding.UTF8.GetBytes(req), true);
174-
Assert.Null(res);
173+
await Assert.ThrowsAsync<DtmFailureException>(async () => await wfgt.Execute(wfName, gid, Encoding.UTF8.GetBytes(req), true));
175174
}
176175

177176
[Fact]
@@ -209,7 +208,7 @@ public async void Rollback_Should_Be_Executed()
209208
wfgt.Register(wfName, handler);
210209
var req = JsonSerializer.Serialize(new { userId = "1", amount = 30 });
211210

212-
var res = await wfgt.Execute(wfName, gid, Encoding.UTF8.GetBytes(req), true);
211+
var res = await Assert.ThrowsAsync<DtmFailureException>(async () => await wfgt.Execute(wfName, gid, Encoding.UTF8.GetBytes(req), true));
213212

214213
func.Verify(x => x.Invoke(It.IsAny<BranchBarrier>()), Times.Once);
215214
}

0 commit comments

Comments
 (0)