diff --git a/metricbeat/module/apache/status/status_test.go b/metricbeat/module/apache/status/status_test.go index f0438be5fb44..327456266058 100644 --- a/metricbeat/module/apache/status/status_test.go +++ b/metricbeat/module/apache/status/status_test.go @@ -147,20 +147,13 @@ func TestFetchEventContents(t *testing.T) { // TestFetchTimeout verifies that the HTTP request times out and an error is // returned. func TestFetchTimeout(t *testing.T) { - wg := sync.WaitGroup{} - wg.Add(1) - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(200) w.Header().Set("Content-Type", "text/plain; charset=ISO-8859-1") w.Write([]byte(response)) - - wg.Wait() + <-r.Context().Done() })) - defer func() { - wg.Done() - server.Close() - }() + defer server.Close() config := map[string]interface{}{ "module": "apache", diff --git a/metricbeat/module/envoyproxy/server/server_test.go b/metricbeat/module/envoyproxy/server/server_test.go index 0c05fd668b18..e58b3517fd3c 100644 --- a/metricbeat/module/envoyproxy/server/server_test.go +++ b/metricbeat/module/envoyproxy/server/server_test.go @@ -118,7 +118,7 @@ func TestFetchTimeout(t *testing.T) { w.WriteHeader(200) w.Header().Set("Content-Type", "text/plain; charset=UTF-8") w.Write([]byte(response)) - time.Sleep(100 * time.Millisecond) + <-r.Context().Done() })) defer server.Close()