Skip to content

Commit

Permalink
Add a test
Browse files Browse the repository at this point in the history
  • Loading branch information
albertvaka committed Oct 17, 2024
1 parent 83e0eb0 commit bb53010
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions pkg/trace/api/evp_proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -505,4 +505,30 @@ func TestE2E(t *testing.T) {
require.Equal(t, http.StatusBadGateway, resp.StatusCode, "Got: ", fmt.Sprint(resp.StatusCode))
assert.Equal(t, "http: proxy error: context deadline exceeded\n", logs)
})

t.Run("chunked-response", func(t *testing.T) {
conf := newTestReceiverConfig()
conf.Site = "us3.datadoghq.com"
conf.Endpoints[0].APIKey = "test_api_key"
conf.EVPProxy.ReceiverTimeout = 1 // in seconds

server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
w.Header().Set("Transfer-Encoding", "chunked")
w.Write([]byte(`Hello`))
w.(http.Flusher).Flush()
time.Sleep(200 * time.Millisecond) // to let the first roundtrip complete
w.Write([]byte(`World`)) // this will be discarded if the context was cancelled
}))

req := httptest.NewRequest("POST", "/mypath/mysubpath?arg=test", bytes.NewReader(randBodyBuf))
req.Header.Set("X-Datadog-EVP-Subdomain", "my.subdomain")
resp, logs := sendRequestThroughForwarderAgainstDummyServer(conf, req, stats, strings.TrimPrefix(server.URL, "http://"))

resp.Body.Close()
require.Equal(t, http.StatusOK, resp.StatusCode, "Got: ", fmt.Sprint(resp.StatusCode))
assert.Equal(t, "", logs)
body, err := io.ReadAll(resp.Body)
assert.NoError(t, err)
assert.Equal(t, "HelloWorld", string(body))
})
}

0 comments on commit bb53010

Please sign in to comment.