mirror of
https://github.com/kubernetes/client-go.git
synced 2025-09-20 10:39:46 +00:00
Use Dial with context
Kubernetes-commit: 5e8e570dbda6ed89af9bc2e0a05e3d94bfdfcb61
This commit is contained in:
committed by
Kubernetes Publisher
parent
4bb327ea2f
commit
4a75b93cb4
@@ -23,12 +23,11 @@ import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/gogo/protobuf/proto"
|
||||
"github.com/googleapis/gnostic/OpenAPIv2"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
@@ -131,31 +130,11 @@ 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) {
|
||||
// first we need to write headers, otherwise http client will complain about
|
||||
// exceeding timeout awaiting headers, only after we can block the call
|
||||
w.Header().Set("Connection", "keep-alive")
|
||||
if wf, ok := w.(http.Flusher); ok {
|
||||
wf.Flush()
|
||||
}
|
||||
<-done
|
||||
}))
|
||||
defer server.Close()
|
||||
defer close(done)
|
||||
client := NewDiscoveryClientForConfigOrDie(&restclient.Config{Host: server.URL, Timeout: 2 * time.Second})
|
||||
_, err := client.ServerGroups()
|
||||
// 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)
|
||||
}
|
||||
|
||||
func TestTimeoutIsSet(t *testing.T) {
|
||||
cfg := &restclient.Config{}
|
||||
setDiscoveryDefaults(cfg)
|
||||
assert.Equal(t, defaultTimeout, cfg.Timeout)
|
||||
}
|
||||
|
||||
func TestGetServerResourcesWithV1Server(t *testing.T) {
|
||||
|
Reference in New Issue
Block a user