Skip to content

Commit

Permalink
Make dataConverterWithoutDeadlock context aware (#1348)
Browse files Browse the repository at this point in the history
  • Loading branch information
Quinn-With-Two-Ns authored Jan 16, 2024
1 parent 0f12265 commit 54e131e
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
4 changes: 2 additions & 2 deletions internal/workflow_deadlock.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,9 @@ func (d *dataConverterWithoutDeadlock) ToStrings(input *commonpb.Payloads) []str
}

func (d *dataConverterWithoutDeadlock) WithWorkflowContext(ctx Context) converter.DataConverter {
return &dataConverterWithoutDeadlock{context: ctx, underlying: d.underlying}
return &dataConverterWithoutDeadlock{context: ctx, underlying: WithWorkflowContext(ctx, d.underlying)}
}

func (d *dataConverterWithoutDeadlock) WithContext(ctx context.Context) converter.DataConverter {
return d
return &dataConverterWithoutDeadlock{context: d.context, underlying: WithContext(ctx, d.underlying)}
}
44 changes: 44 additions & 0 deletions internal/workflow_deadlock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,47 @@ func (s *slowToPayloadsConverter) ToPayloads(value ...interface{}) (*commonpb.Pa
time.Sleep(600 * time.Millisecond)
return s.DataConverter.ToPayloads(value...)
}

func TestDataConverterWithoutDeadlockDetectionContext(t *testing.T) {
contextAwareDataConverter := NewContextAwareDataConverter(converter.GetDefaultDataConverter())
conv := DataConverterWithoutDeadlockDetection(contextAwareDataConverter)

t.Parallel()
t.Run("default", func(t *testing.T) {
t.Parallel()
payload, _ := conv.ToPayload("test")
result := conv.ToString(payload)

require.Equal(t, `"test"`, result)
})
t.Run("implements ContextAware", func(t *testing.T) {
t.Parallel()
_, ok := conv.(ContextAware)
require.True(t, ok)
})
t.Run("with activity context", func(t *testing.T) {
t.Parallel()
ctx := context.Background()
ctx = context.WithValue(ctx, ContextAwareDataConverterContextKey, "e")

dc := WithContext(ctx, conv)

payload, _ := dc.ToPayload("test")
result := dc.ToString(payload)

require.Equal(t, `"t?st"`, result)
})
t.Run("with workflow context", func(t *testing.T) {
t.Parallel()
ctx := Background()
ctx = WithValue(ctx, ContextAwareDataConverterContextKey, "e")

dc := WithWorkflowContext(ctx, conv)

payload, _ := dc.ToPayload("test")
result := dc.ToString(payload)

require.Equal(t, `"t?st"`, result)
})

}

0 comments on commit 54e131e

Please sign in to comment.