Skip to content

Commit e756c08

Browse files
authored
Merge pull request #307 from cschleiden/only-panic-in-test
Do not panic at runtime for pending futures
2 parents 8757db2 + f195952 commit e756c08

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

internal/workflow/executor.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"log/slog"
88
"reflect"
99
"slices"
10+
"testing"
1011

1112
"github.com/benbjohnson/clock"
1213
"github.com/cschleiden/go-workflows/backend"
@@ -185,6 +186,7 @@ func (e *executor) ExecuteTask(ctx context.Context, t *backend.WorkflowTask) (*E
185186
if err != nil {
186187
logger.Error("Error while executing new events", "error", err)
187188

189+
// Transition workflow to error state
188190
e.workflowCompleted(nil, err)
189191
}
190192
}
@@ -266,7 +268,6 @@ func (e *executor) executeNewEvents(newEvents []*history.Event) ([]*history.Even
266268
}
267269

268270
if e.workflow.Completed() {
269-
// TODO: Is this too early? We haven't committed some of the commands
270271
if e.workflowState.HasPendingFutures() {
271272
var pending []string
272273
pf := e.workflowState.PendingFutureNames()
@@ -275,8 +276,11 @@ func (e *executor) executeNewEvents(newEvents []*history.Event) ([]*history.Even
275276
}
276277
slices.Sort(pending)
277278

278-
e.logger.Error("workflow completed, but there are still pending futures", "pending", pending)
279-
panic(fmt.Sprintf("workflow completed, but there are still pending futures: %s", pending))
279+
if testing.Testing() {
280+
panic(fmt.Sprintf("workflow completed, but there are still pending futures: %s", pending))
281+
}
282+
283+
return newEvents, fmt.Errorf("workflow completed, but there are still pending futures: %s", pending)
280284
}
281285

282286
if canErr, ok := e.workflow.Error().(*continueasnew.Error); ok {

0 commit comments

Comments
 (0)