From bb53010b07a4d45f9102f71dd97e90947f0a5032 Mon Sep 17 00:00:00 2001 From: Albert Vaca Cintora Date: Thu, 17 Oct 2024 21:34:36 +0200 Subject: [PATCH] Add a test --- pkg/trace/api/evp_proxy_test.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/pkg/trace/api/evp_proxy_test.go b/pkg/trace/api/evp_proxy_test.go index 3016b6e5ef53cf..08638a81ce0927 100644 --- a/pkg/trace/api/evp_proxy_test.go +++ b/pkg/trace/api/evp_proxy_test.go @@ -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)) + }) }