Skip to content

Commit 1c1a0b7

Browse files
authored
Merge pull request #255 from cschleiden/flaky-tests
Improve flaky redis unit tests
2 parents 0ee3530 + 8d00d28 commit 1c1a0b7

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

backend/redis/expire_test.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func Test_AutoExpiration(t *testing.T) {
1818
t.Skip()
1919
}
2020

21-
autoExpirationTime := time.Second * 1
21+
autoExpirationTime := time.Second * 2
2222

2323
redisClient := getClient()
2424
setup := getCreateBackend(redisClient, WithAutoExpiration(autoExpirationTime))
@@ -45,7 +45,7 @@ func Test_AutoExpiration(t *testing.T) {
4545
require.NoError(t, c.WaitForWorkflowInstance(ctx, wfi, time.Second*10))
4646

4747
// Wait for redis to expire the keys
48-
time.Sleep(autoExpirationTime)
48+
time.Sleep(autoExpirationTime * 2)
4949

5050
_, err = b.GetWorkflowInstanceState(ctx, wfi)
5151
require.ErrorIs(t, err, backend.ErrInstanceNotFound)
@@ -59,7 +59,7 @@ func Test_AutoExpiration_SubWorkflow(t *testing.T) {
5959
t.Skip()
6060
}
6161

62-
autoExpirationTime := time.Second * 1
62+
autoExpirationTime := time.Second * 2
6363

6464
redisClient := getClient()
6565
setup := getCreateBackend(redisClient, WithAutoExpiration(autoExpirationTime))
@@ -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
@@ -79,6 +84,9 @@ func Test_AutoExpiration_SubWorkflow(t *testing.T) {
7984
swfInstanceID := uuid.NewString()
8085

8186
wf := func(ctx workflow.Context) (int, error) {
87+
l := workflow.Logger(ctx)
88+
l.Debug("Starting sub workflow", "instanceID", swfInstanceID)
89+
8290
r, err := workflow.CreateSubWorkflowInstance[int](ctx, workflow.SubWorkflowOptions{
8391
InstanceID: swfInstanceID,
8492
}, swf).Get(ctx)
@@ -101,12 +109,9 @@ func Test_AutoExpiration_SubWorkflow(t *testing.T) {
101109
require.Equal(t, 42, r)
102110

103111
// Wait for redis to expire the keys
104-
time.Sleep(autoExpirationTime)
112+
time.Sleep(autoExpirationTime * 2)
105113

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

0 commit comments

Comments
 (0)