Deflake the max-in-flight limit test
This commit is contained in:
parent
f8a9943d90
commit
c3a8dc0494
@ -66,10 +66,17 @@ func TestMaxInFlight(t *testing.T) {
|
|||||||
|
|
||||||
re := regexp.MustCompile("[.*\\/watch][^\\/proxy.*]")
|
re := regexp.MustCompile("[.*\\/watch][^\\/proxy.*]")
|
||||||
|
|
||||||
|
// Calls verifies that the server is actually blocked up before running the rest of the test
|
||||||
|
calls := &sync.WaitGroup{}
|
||||||
|
calls.Add(Iterations * 3)
|
||||||
|
|
||||||
server := httptest.NewServer(MaxInFlightLimit(sem, re, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
server := httptest.NewServer(MaxInFlightLimit(sem, re, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
if strings.Contains(r.URL.Path, "dontwait") {
|
if strings.Contains(r.URL.Path, "dontwait") {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if calls != nil {
|
||||||
|
calls.Done()
|
||||||
|
}
|
||||||
block.Wait()
|
block.Wait()
|
||||||
})))
|
})))
|
||||||
defer server.Close()
|
defer server.Close()
|
||||||
@ -81,6 +88,7 @@ func TestMaxInFlight(t *testing.T) {
|
|||||||
expectHTTP(server.URL+"/foo/bar/watch", http.StatusOK, t)
|
expectHTTP(server.URL+"/foo/bar/watch", http.StatusOK, t)
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < Iterations; i++ {
|
for i := 0; i < Iterations; i++ {
|
||||||
// These should hang waiting on block...
|
// These should hang waiting on block...
|
||||||
go func() {
|
go func() {
|
||||||
@ -95,15 +103,17 @@ func TestMaxInFlight(t *testing.T) {
|
|||||||
expectHTTP(server.URL, http.StatusOK, t)
|
expectHTTP(server.URL, http.StatusOK, t)
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
// There's really no more elegant way to do this. I could use a WaitGroup, but even then
|
calls.Wait()
|
||||||
// it'd still be racy.
|
calls = nil
|
||||||
time.Sleep(1 * time.Second)
|
|
||||||
expectHTTP(server.URL+"/dontwait/watch", http.StatusOK, t)
|
|
||||||
|
|
||||||
// Do this multiple times to show that it rate limit rejected requests don't block.
|
// Do this multiple times to show that it rate limit rejected requests don't block.
|
||||||
for i := 0; i < 2; i++ {
|
for i := 0; i < 2; i++ {
|
||||||
expectHTTP(server.URL, errors.StatusTooManyRequests, t)
|
expectHTTP(server.URL, errors.StatusTooManyRequests, t)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Validate that non-accounted URLs still work
|
||||||
|
expectHTTP(server.URL+"/dontwait/watch", http.StatusOK, t)
|
||||||
|
|
||||||
block.Done()
|
block.Done()
|
||||||
|
|
||||||
// Show that we recover from being blocked up.
|
// Show that we recover from being blocked up.
|
||||||
|
Loading…
Reference in New Issue
Block a user