-
Notifications
You must be signed in to change notification settings - Fork 28
cre-2803: http boundry blocker investigation (common side) #1955
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
79bc0d7
cre-2803: http boundry blocker investigation
mchain0 ae6bc91
Merge branch 'main' into cre-2802-http-boundry-blocker-investigation
mchain0 955ee33
Merge branch 'main' into cre-2802-http-boundry-blocker-investigation
mchain0 5b4a641
cre-2802: minor improvements
mchain0 d64c37e
cre-2802: minor fixes
mchain0 4aa27e1
Merge branch 'main' into cre-2802-http-boundry-blocker-investigation
mchain0 e6e9575
cre-2802: assert improvements
mchain0 2a1d5ad
Merge branch 'main' into cre-2802-http-boundry-blocker-investigation
mchain0 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| package host | ||
|
|
||
| import ( | ||
| "context" | ||
| "sync/atomic" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
| "google.golang.org/protobuf/types/known/anypb" | ||
| "google.golang.org/protobuf/types/known/emptypb" | ||
|
|
||
| sdkpb "github.com/smartcontractkit/chainlink-protos/cre/go/sdk" | ||
| wfpb "github.com/smartcontractkit/chainlink-protos/workflows/go/v2" | ||
| ) | ||
|
|
||
| // awaitOrderStub implements ExecutionHelper for testing awaitCapabilities ordering. | ||
| type awaitOrderStub struct { | ||
| unblock chan struct{} | ||
| id2Done chan struct{} | ||
| } | ||
|
|
||
| func (a *awaitOrderStub) CallCapability(_ context.Context, req *sdkpb.CapabilityRequest) (*sdkpb.CapabilityResponse, error) { | ||
| payload, err := anypb.New(&emptypb.Empty{}) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| ok := &sdkpb.CapabilityResponse{ | ||
| Response: &sdkpb.CapabilityResponse_Payload{ | ||
| Payload: payload, | ||
| }, | ||
| } | ||
| if req.CallbackId == 1 { | ||
| <-a.unblock | ||
| } | ||
| if req.CallbackId == 2 && a.id2Done != nil { | ||
| close(a.id2Done) | ||
| } | ||
| return ok, nil | ||
| } | ||
|
|
||
| func (a *awaitOrderStub) GetSecrets(context.Context, *sdkpb.GetSecretsRequest) ([]*sdkpb.SecretResponse, error) { | ||
| return nil, nil | ||
| } | ||
|
|
||
| func (a *awaitOrderStub) GetWorkflowExecutionID() string { return "" } | ||
|
|
||
| func (a *awaitOrderStub) GetNodeTime() time.Time { return time.Time{} } | ||
|
|
||
| func (a *awaitOrderStub) GetDONTime() (time.Time, error) { return time.Time{}, nil } | ||
|
|
||
| func (a *awaitOrderStub) EmitUserLog(string) error { return nil } | ||
|
|
||
| func (a *awaitOrderStub) EmitUserMetric(context.Context, *wfpb.WorkflowUserMetric) error { return nil } | ||
|
|
||
| var _ ExecutionHelper = (*awaitOrderStub)(nil) | ||
|
|
||
| // TestAwaitCapabilities_headOfLineBlocksOnEarlierID proves awaitCapabilities reads from | ||
| // callback channels in acr.Ids order (head-of-line): it cannot finish until an earlier ID | ||
| // completes, even when a later callback finishes first. AwaitCapabilitiesResponse.Responses is a | ||
| // map keyed by CallbackId, not a slice ordered by completion time. | ||
| func TestAwaitCapabilities_headOfLineBlocksOnEarlierID(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| unblock := make(chan struct{}) | ||
| id2Done := make(chan struct{}) | ||
| stub := &awaitOrderStub{unblock: unblock, id2Done: id2Done} | ||
|
|
||
| exec := &execution[*sdkpb.ExecutionResult]{ | ||
| ctx: t.Context(), | ||
| capabilityResponses: make(map[int32]<-chan *sdkpb.CapabilityResponse), | ||
| executor: stub, | ||
| } | ||
|
|
||
| req := func(id int32) *sdkpb.CapabilityRequest { | ||
| return &sdkpb.CapabilityRequest{CallbackId: id} | ||
| } | ||
|
|
||
| require.NoError(t, exec.callCapAsync(t.Context(), req(1))) | ||
| require.NoError(t, exec.callCapAsync(t.Context(), req(2))) | ||
|
|
||
| var awaitFinished atomic.Bool | ||
| var awaitResp *sdkpb.AwaitCapabilitiesResponse | ||
| var awaitErr error | ||
| go func() { | ||
| awaitResp, awaitErr = exec.awaitCapabilities(t.Context(), &sdkpb.AwaitCapabilitiesRequest{Ids: []int32{1, 2}}) | ||
| awaitFinished.Store(true) | ||
| }() | ||
|
|
||
| select { | ||
| case <-id2Done: | ||
| case <-time.After(2 * time.Second): | ||
| t.Fatal("CallCapability for callback 2 did not return while callback 1 was still blocked") | ||
| } | ||
| require.False(t, awaitFinished.Load(), "awaitCapabilities returned before callback 1 was unblocked; head-of-line invariant violated") | ||
|
|
||
| // Unblock callback 1 so the first channel receive in awaitCapabilities can complete. | ||
| close(unblock) | ||
|
|
||
| require.Eventually(t, func() bool { return awaitFinished.Load() }, 2*time.Second, 10*time.Millisecond, | ||
| "awaitCapabilities did not complete after unblocking callback 1") | ||
| require.NoError(t, awaitErr) | ||
| require.Len(t, awaitResp.Responses, 2) | ||
| require.NotNil(t, awaitResp.Responses[1], "expected entry keyed by CallbackId 1 (map is by id, not completion order)") | ||
| require.NotNil(t, awaitResp.Responses[2], "expected entry keyed by CallbackId 2") | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.