Skip to content

Commit baf44d5

Browse files
committed
Add test to ensure instance id can be re-used after workflow is finished
1 parent 5120f1d commit baf44d5

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

backend/test/e2e.go

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ func EndToEndBackendTest(t *testing.T, setup func(options ...backend.BackendOpti
203203
},
204204
},
205205
{
206-
name: "SubWorkflow_DuplicateInstanceID",
206+
name: "SubWorkflow_DuplicateActiveInstanceID",
207207
f: func(t *testing.T, ctx context.Context, c *client.Client, w *worker.Worker, b TestBackend) {
208208
swf := func(ctx workflow.Context, i int) (int, error) {
209209
workflow.NewSignalChannel[any](ctx, "signal").Receive(ctx)
@@ -241,6 +241,40 @@ func EndToEndBackendTest(t *testing.T, setup func(options ...backend.BackendOpti
241241
require.Error(t, err, backend.ErrInstanceAlreadyExists.Error())
242242
},
243243
},
244+
{
245+
name: "SubWorkflow_DuplicateInactiveInstanceID",
246+
f: func(t *testing.T, ctx context.Context, c *client.Client, w *worker.Worker, b TestBackend) {
247+
swf := func(ctx workflow.Context, i int) (int, error) {
248+
return i * 2, nil
249+
}
250+
wf := func(ctx workflow.Context) (int, error) {
251+
// Let sub-workflow run to completion
252+
r, err := workflow.CreateSubWorkflowInstance[int](ctx, workflow.SubWorkflowOptions{
253+
InstanceID: "subworkflow",
254+
}, swf, 1).Get(ctx)
255+
if err != nil {
256+
return 0, err
257+
}
258+
259+
// Run another subworkflow with the same ID
260+
r, err = workflow.CreateSubWorkflowInstance[int](ctx, workflow.SubWorkflowOptions{
261+
InstanceID: "subworkflow",
262+
}, swf, 2).Get(ctx)
263+
if err != nil {
264+
return 0, err
265+
}
266+
267+
return r, nil
268+
}
269+
register(t, ctx, w, []interface{}{wf, swf}, nil)
270+
271+
instance := runWorkflow(t, ctx, c, wf)
272+
273+
r, err := client.GetWorkflowResult[int](ctx, c, instance, time.Second*20)
274+
require.NoError(t, err)
275+
require.Equal(t, 4, r)
276+
},
277+
},
244278
{
245279
name: "SubWorkflow_PropagateCancellation",
246280
f: func(t *testing.T, ctx context.Context, c *client.Client, w *worker.Worker, b TestBackend) {

0 commit comments

Comments
 (0)