Skip to content

Commit 5a39b16

Browse files
committed
Fix a race condition in the CRE sdk standard test
1 parent ae45911 commit 5a39b16

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

pkg/workflows/wasm/host/standard_test.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,18 @@ func TestStandardCapabilityCallsAreAsync(t *testing.T) {
9595
assert.Equal(t, "PerformAction", request.Method)
9696
input := &basicaction.Inputs{}
9797
assert.NoError(t, request.Payload.UnmarshalTo(input))
98-
assert.False(t, callsSeen[input.InputThing])
99-
callsSeen[input.InputThing] = true
100-
payload, err := anypb.New(&basicaction.Outputs{AdaptedThing: fmt.Sprintf("%t", input.InputThing)})
101-
require.NoError(t, err)
10298

10399
// Don't return until the second call has been executed
100+
// Take the lock before accessing callsSeen to avoid a race
104101
if input.InputThing {
105102
mt.Lock()
106103
}
104+
105+
assert.False(t, callsSeen[input.InputThing])
106+
callsSeen[input.InputThing] = true
107+
payload, err := anypb.New(&basicaction.Outputs{AdaptedThing: fmt.Sprintf("%t", input.InputThing)})
108+
require.NoError(t, err)
109+
107110
defer mt.Unlock()
108111
return &sdk.CapabilityResponse{
109112
Response: &sdk.CapabilityResponse_Payload{Payload: payload},

0 commit comments

Comments
 (0)