make TestGetServerGroupsWithTimeout more reliable

Kubernetes-commit: e7620e814aebca184160f2ae5ef243f5dcd1f409
This commit is contained in:
David Eads 2018-05-15 12:47:23 -04:00 committed by Kubernetes Publisher
parent 79540301d5
commit ef648e2917

View File

@ -136,20 +136,26 @@ func TestGetServerGroupsWithTimeout(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
// first we need to write headers, otherwise http client will complain about
// exceeding timeout awaiting headers, only after we can block the call
w.WriteHeader(http.StatusOK)
w.Header().Set("Connection", "keep-alive")
if wf, ok := w.(http.Flusher); ok {
wf.Flush()
}
<-done
}))
defer server.Close()
defer close(done)
tmp := defaultTimeout
defaultTimeout = 2 * time.Second
client := NewDiscoveryClientForConfigOrDie(&restclient.Config{Host: server.URL})
client := NewDiscoveryClientForConfigOrDie(&restclient.Config{Host: server.URL, Timeout: 2 * time.Second})
_, err := client.ServerGroups()
if err == nil || !strings.Contains(err.Error(), "deadline") {
// the error we're getting here is wrapped in errors.errorString which makes
// it impossible to unwrap and check it's attributes, so instead we're checking
// the textual output which is presenting http.httpError with timeout set to true
if err == nil {
t.Fatal("missing error")
}
if !strings.Contains(err.Error(), "timeout:true") &&
!strings.Contains(err.Error(), "context.deadlineExceededError") {
t.Fatalf("unexpected error: %v", err)
}
done <- true
defaultTimeout = tmp
}
func TestGetServerResourcesWithV1Server(t *testing.T) {