Fix discovery default timeout test

Kubernetes-commit: af2353f8a3ab06ca105d15a0b1b27605e4093da5
This commit is contained in:
Maciej Szulik 2018-04-24 17:05:56 +02:00 committed by Kubernetes Publisher
parent d36be08adf
commit 581437501a

View File

@ -131,18 +131,23 @@ func TestGetServerGroupsWithBrokenServer(t *testing.T) {
}
}
func TestGetServerGroupsWithTimeout(t *testing.T) {
done := make(chan bool)
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
time.Sleep(2 * time.Second)
// 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)
<-done
}))
defer server.Close()
defer close(done)
tmp := defaultTimeout
defaultTimeout = 1 * time.Second
defaultTimeout = 2 * time.Second
client := NewDiscoveryClientForConfigOrDie(&restclient.Config{Host: server.URL})
_, err := client.ServerGroups()
if err == nil || strings.Contains(err.Error(), "deadline") {
if err == nil || !strings.Contains(err.Error(), "deadline") {
t.Fatalf("unexpected error: %v", err)
}
done <- true
defaultTimeout = tmp
}