Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lambda/invoke_loop_gte_go122_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,10 @@ func TestRuntimeAPILoopWithConcurrency(t *testing.T) {
endpoint := strings.Split(ts.URL, "://")[1]
expectedError := fmt.Sprintf("failed to GET http://%s/2018-06-01/runtime/invocation/next: got unexpected status code: 410", endpoint)
assert.EqualError(t, startRuntimeAPILoopWithConcurrency(endpoint, handler, concurrency), expectedError)
record.lock.Lock()
assert.GreaterOrEqual(t, record.nGets, nInvokes+1)
assert.Equal(t, nInvokes, record.nPosts)
record.lock.Unlock()
assert.Equal(t, int32(concurrency), maxActive.Load())
responses := make(map[string]int)
for _, response := range record.responses {
Expand Down
7 changes: 7 additions & 0 deletions lambda/invoke_loop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ func defaultInvokeMetadata() eventMetadata {
}

func runtimeAPIServer(eventPayload string, failAfter int, overrides ...eventMetadata) (*httptest.Server, *requestRecord) {
ctx, cancel := context.WithCancel(context.Background())
numInvokesRequested := 0
numInvokesRequestedLock := sync.Mutex{}
record := &requestRecord{}
Expand All @@ -461,6 +462,7 @@ func runtimeAPIServer(eventPayload string, failAfter int, overrides ...eventMeta
record.nGets++
record.lock.Unlock()
if shouldFail {
<-ctx.Done() // wait for all handlers to finish.
w.WriteHeader(http.StatusGone)
_, _ = w.Write([]byte("END THE TEST!"))
return
Expand All @@ -483,10 +485,15 @@ func runtimeAPIServer(eventPayload string, failAfter int, overrides ...eventMeta
w.WriteHeader(http.StatusAccepted)
record.lock.Lock()
record.nPosts++
done := record.nPosts >= failAfter
record.responses = append(record.responses, response.Bytes())
record.contentTypes = append(record.contentTypes, r.Header.Get("Content-Type"))
record.xrayCauses = append(record.xrayCauses, r.Header.Get(headerXRayErrorCause))
record.lock.Unlock()
if done {
// all handlers are done, cancel the context to let the GET handler exit.
cancel()
}
default:
w.WriteHeader(http.StatusBadRequest)
}
Expand Down