Skip to content

Commit

Permalink
wait until all request are handled
Browse files Browse the repository at this point in the history
Change-Id: Ia81b85668d6f9966fa26e5b744bf5498a3f34768
  • Loading branch information
shunjiazhu committed Nov 12, 2024
1 parent a34c7dd commit 47d9d3b
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions plugins/flusher/prometheus/flusher_prometheus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"net/http"
"sort"
"strings"
"sync"
"testing"
"time"

Expand Down Expand Up @@ -117,8 +118,10 @@ func TestPrometheusFlusher_ShouldWriteToRemoteStorageSuccess_GivenCorrectDataWit

httpmock.Activate()
defer httpmock.DeactivateAndReset()
var wg sync.WaitGroup

httpmock.RegisterResponder("POST", endpoint, func(req *http.Request) (*http.Response, error) {
defer wg.Done()
username, password, err := parseBasicAuth(req.Header.Get("Authorization"))
if err != nil {
return httpmock.NewStringResponse(http.StatusUnauthorized, "Invalid Authorization"), fmt.Errorf("invalid authentication: %w", err)
Expand Down Expand Up @@ -238,10 +241,12 @@ func TestPrometheusFlusher_ShouldWriteToRemoteStorageSuccess_GivenCorrectDataWit
}
expectedWriteRequest = sortPromLabelsInWriteRequest(expectedWriteRequest)
httpmock.ZeroCallCounters()
wg.Add(2)
err := flusher.Export(groupEventsSlice, nil)
So(err, ShouldBeNil)

time.Sleep(1 * time.Second) // guarantee that all http requests are handled
wg.Wait()

err = flusher.Stop()
So(err, ShouldBeNil)
Expand Down

0 comments on commit 47d9d3b

Please sign in to comment.