Skip to content

Commit e591a0f

Browse files
committed
Ensure worker is stopped even when test fails
1 parent 0ee3530 commit e591a0f

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

backend/redis/expire_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ func Test_AutoExpiration_SubWorkflow(t *testing.T) {
7171
ctx, cancel := context.WithCancel(context.Background())
7272

7373
require.NoError(t, w.Start(ctx))
74+
defer func() {
75+
cancel()
76+
77+
require.NoError(t, w.WaitForCompletion())
78+
}()
7479

7580
swf := func(ctx workflow.Context) (int, error) {
7681
return 42, nil
@@ -101,12 +106,9 @@ func Test_AutoExpiration_SubWorkflow(t *testing.T) {
101106
require.Equal(t, 42, r)
102107

103108
// Wait for redis to expire the keys
104-
time.Sleep(autoExpirationTime)
109+
time.Sleep(autoExpirationTime * 2)
105110

106111
// Main workflow should now be expired
107112
_, err = b.GetWorkflowInstanceState(ctx, wfi)
108113
require.ErrorIs(t, err, backend.ErrInstanceNotFound)
109-
110-
cancel()
111-
require.NoError(t, w.WaitForCompletion())
112114
}

0 commit comments

Comments
 (0)