diff --git a/api/api_test.go b/api/api_test.go index 0048ecdfe67..dbdb62049a1 100644 --- a/api/api_test.go +++ b/api/api_test.go @@ -10,6 +10,7 @@ import ( "net/url" "os" "strings" + "sync" "testing" "time" @@ -538,3 +539,36 @@ func TestCloneHttpClient(t *testing.T) { }) } + +func TestClient_HeaderRaceCondition(t *testing.T) { + require := require.New(t) + + conf := DefaultConfig() + conf.Headers = map[string][]string{ + "test-header": {"a"}, + } + client, err := NewClient(conf) + require.NoError(err) + + wg := sync.WaitGroup{} + wg.Add(2) + + go func() { + for i := 0; i < 500; i++ { + req, err := client.newRequest("GET", "/any/path/will/do") + require.NoError(err) + _, _ = req.toHTTP() + } + wg.Done() + }() + go func() { + for i := 0; i < 500; i++ { + req, err := client.newRequest("GET", "/any/path/will/do") + require.NoError(err) + _, _ = req.toHTTP() + } + wg.Done() + }() + + wg.Wait() +}