Skip to content

Commit

Permalink
Wait for context finalization to provoke http timeouts on tests (elas…
Browse files Browse the repository at this point in the history
…tic#8074)

Wait for request context to be done, that is closed when the server is
stopped.
  • Loading branch information
jsoriano authored and ruflin committed Aug 28, 2018
1 parent 6625835 commit 6111dc6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 10 deletions.
11 changes: 2 additions & 9 deletions metricbeat/module/apache/status/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion metricbeat/module/envoyproxy/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit 6111dc6

Please sign in to comment.