Skip to content

Commit 20ddb2f

Browse files
authored
Merge pull request #287 from decibelcooper/fix_redis_diag_panic
fix: redis diagnostics panic
2 parents 5096b37 + 92d1f7f commit 20ddb2f

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

backend/redis/diagnostics.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,13 @@ func (rb *redisBackend) GetWorkflowInstances(ctx context.Context, afterInstanceI
5959

6060
var instanceRefs []*diag.WorkflowInstanceRef
6161
for _, instance := range instances {
62+
instStr, ok := instance.(string)
63+
if !ok {
64+
continue
65+
}
66+
6267
var state instanceState
63-
if err := json.Unmarshal([]byte(instance.(string)), &state); err != nil {
68+
if err := json.Unmarshal([]byte(instStr), &state); err != nil {
6469
return nil, fmt.Errorf("unmarshaling instance state: %w", err)
6570
}
6671

backend/redis/expire_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/cschleiden/go-workflows/worker"
1111
"github.com/cschleiden/go-workflows/workflow"
1212
"github.com/google/uuid"
13+
"github.com/stretchr/testify/assert"
1314
"github.com/stretchr/testify/require"
1415
)
1516

@@ -50,6 +51,11 @@ func Test_AutoExpiration(t *testing.T) {
5051
_, err = b.GetWorkflowInstanceState(ctx, wfi)
5152
require.ErrorIs(t, err, backend.ErrInstanceNotFound)
5253

54+
// Check that the instance is gone from the list of instances
55+
insts, err := b.(*redisBackend).GetWorkflowInstances(ctx, "", "", 1)
56+
require.NoError(t, err)
57+
assert.Len(t, insts, 0)
58+
5359
cancel()
5460
require.NoError(t, w.WaitForCompletion())
5561
}

0 commit comments

Comments
 (0)