Skip to content

Commit 85da35b

Browse files
committed
test that an execution race was caught
1 parent 676e320 commit 85da35b

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

dbos/workflows_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,6 +1285,7 @@ func TestWorkflowRecovery(t *testing.T) {
12851285
recoveryCounters []int64
12861286
recoveryEvents []*Event
12871287
blockingEvents []*Event
1288+
secondStepErrors []error
12881289
)
12891290

12901291
recoveryWorkflow := func(dbosCtx DBOSContext, index int) (int64, error) {
@@ -1306,6 +1307,7 @@ func TestWorkflowRecovery(t *testing.T) {
13061307
return fmt.Sprintf("completed-%d", index), nil
13071308
}, WithStepName(fmt.Sprintf("BlockingStep-%d", index)))
13081309
if err != nil {
1310+
secondStepErrors = append(secondStepErrors, err)
13091311
return 0, err
13101312
}
13111313

@@ -1324,6 +1326,7 @@ func TestWorkflowRecovery(t *testing.T) {
13241326
recoveryCounters = make([]int64, numWorkflows)
13251327
recoveryEvents = make([]*Event, numWorkflows)
13261328
blockingEvents = make([]*Event, numWorkflows)
1329+
secondStepErrors = make([]error, 0)
13271330

13281331
// Create events for each workflow
13291332
for i := range numWorkflows {
@@ -1425,6 +1428,16 @@ func TestWorkflowRecovery(t *testing.T) {
14251428
assert.Nil(t, steps[0].Error, "workflow %d first step should not have error", i)
14261429
assert.Nil(t, steps[1].Error, "workflow %d second step should not have error", i)
14271430
}
1431+
1432+
// At least 5 of the 2nd steps should have errored due to execution race
1433+
// Check they are DBOSErrors with StepExecutionError wrapping a ConflictingIDError
1434+
require.GreaterOrEqual(t, len(secondStepErrors), 5, "expected at least 5 errors from second steps due to recovery race, got %d", len(secondStepErrors))
1435+
for _, err := range secondStepErrors {
1436+
dbosErr, ok := err.(*DBOSError)
1437+
require.True(t, ok, "expected error to be of type *DBOSError, got %T", err)
1438+
require.Equal(t, StepExecutionError, dbosErr.Code, "expected error code to be StepExecutionError, got %v", dbosErr.Code)
1439+
require.True(t, errors.Is(dbosErr.Unwrap(), &DBOSError{Code: ConflictingIDError}), "expected underlying error to be ConflictingIDError, got %T", dbosErr.Unwrap())
1440+
}
14281441
})
14291442
}
14301443

0 commit comments

Comments
 (0)