Merge pull request #14688 from brendandburns/fix3

Auto commit by PR queue bot
This commit is contained in:
k8s-merge-robot 2015-09-28 23:08:19 -07:00
commit 226d97fa29

View File

@ -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.