mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-04 09:49:50 +00:00
Merge pull request #94529 from liggitt/deflake-units
Deflake unit tests
This commit is contained in:
commit
a23cf7077e
@ -20,6 +20,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"os"
|
"os"
|
||||||
@ -363,6 +364,15 @@ profiles:
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
makeListener := func(t *testing.T) net.Listener {
|
||||||
|
t.Helper()
|
||||||
|
l, err := net.Listen("tcp", ":0")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
return l
|
||||||
|
}
|
||||||
|
|
||||||
for _, tc := range testcases {
|
for _, tc := range testcases {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
fs := pflag.NewFlagSet("test", pflag.PanicOnError)
|
fs := pflag.NewFlagSet("test", pflag.PanicOnError)
|
||||||
@ -370,6 +380,15 @@ profiles:
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// use listeners instead of static ports so parallel test runs don't conflict
|
||||||
|
opts.SecureServing.Listener = makeListener(t)
|
||||||
|
defer opts.SecureServing.Listener.Close()
|
||||||
|
opts.CombinedInsecureServing.Metrics.Listener = makeListener(t)
|
||||||
|
defer opts.CombinedInsecureServing.Metrics.Listener.Close()
|
||||||
|
opts.CombinedInsecureServing.Healthz.Listener = makeListener(t)
|
||||||
|
defer opts.CombinedInsecureServing.Healthz.Listener.Close()
|
||||||
|
|
||||||
for _, f := range opts.Flags().FlagSets {
|
for _, f := range opts.Flags().FlagSets {
|
||||||
fs.AddFlagSet(f)
|
fs.AddFlagSet(f)
|
||||||
}
|
}
|
||||||
@ -379,12 +398,10 @@ profiles:
|
|||||||
|
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
defer cancel()
|
defer cancel()
|
||||||
cc, sched, err := Setup(ctx, opts)
|
_, sched, err := Setup(ctx, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
defer cc.SecureServing.Listener.Close()
|
|
||||||
defer cc.InsecureServing.Listener.Close()
|
|
||||||
|
|
||||||
gotPlugins := make(map[string]map[string][]kubeschedulerconfig.Plugin)
|
gotPlugins := make(map[string]map[string][]kubeschedulerconfig.Plugin)
|
||||||
for n, p := range sched.Profiles {
|
for n, p := range sched.Profiles {
|
||||||
|
@ -61,7 +61,13 @@ func unsetEnv(key string) func() {
|
|||||||
|
|
||||||
func TestHTTPProbeProxy(t *testing.T) {
|
func TestHTTPProbeProxy(t *testing.T) {
|
||||||
res := "welcome to http probe proxy"
|
res := "welcome to http probe proxy"
|
||||||
localProxy := "http://127.0.0.1:9098/"
|
|
||||||
|
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
fmt.Fprint(w, res)
|
||||||
|
}))
|
||||||
|
defer server.Close()
|
||||||
|
|
||||||
|
localProxy := server.URL
|
||||||
|
|
||||||
defer setEnv("http_proxy", localProxy)()
|
defer setEnv("http_proxy", localProxy)()
|
||||||
defer setEnv("HTTP_PROXY", localProxy)()
|
defer setEnv("HTTP_PROXY", localProxy)()
|
||||||
@ -71,16 +77,6 @@ func TestHTTPProbeProxy(t *testing.T) {
|
|||||||
followNonLocalRedirects := true
|
followNonLocalRedirects := true
|
||||||
prober := New(followNonLocalRedirects)
|
prober := New(followNonLocalRedirects)
|
||||||
|
|
||||||
go func() {
|
|
||||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
fmt.Fprint(w, res)
|
|
||||||
})
|
|
||||||
err := http.ListenAndServe(":9098", nil)
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("Failed to start foo server: localhost:9098")
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
// take some time to wait server boot
|
// take some time to wait server boot
|
||||||
time.Sleep(2 * time.Second)
|
time.Sleep(2 * time.Second)
|
||||||
url, err := url.Parse("http://example.com")
|
url, err := url.Parse("http://example.com")
|
||||||
|
@ -342,6 +342,7 @@ func TestClientReceivedGOAWAY(t *testing.T) {
|
|||||||
|
|
||||||
for _, tc := range cases {
|
for _, tc := range cases {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
|
var mu sync.Mutex
|
||||||
// localAddr indicates how many TCP connection set up
|
// localAddr indicates how many TCP connection set up
|
||||||
localAddr := make([]string, 0)
|
localAddr := make([]string, 0)
|
||||||
|
|
||||||
@ -350,7 +351,10 @@ func TestClientReceivedGOAWAY(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpect connection err: %v", err)
|
t.Fatalf("unexpect connection err: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mu.Lock()
|
||||||
localAddr = append(localAddr, conn.LocalAddr().String())
|
localAddr = append(localAddr, conn.LocalAddr().String())
|
||||||
|
mu.Unlock()
|
||||||
return
|
return
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -435,6 +439,8 @@ func TestGOAWAYHTTP1Requests(t *testing.T) {
|
|||||||
// TestGOAWAYConcurrency tests GOAWAY frame will not affect concurrency requests in a single http client instance.
|
// TestGOAWAYConcurrency tests GOAWAY frame will not affect concurrency requests in a single http client instance.
|
||||||
// Known issues in history: https://github.com/kubernetes/kubernetes/issues/91131.
|
// Known issues in history: https://github.com/kubernetes/kubernetes/issues/91131.
|
||||||
func TestGOAWAYConcurrency(t *testing.T) {
|
func TestGOAWAYConcurrency(t *testing.T) {
|
||||||
|
t.Skip("disabled because of https://github.com/kubernetes/kubernetes/issues/94532")
|
||||||
|
|
||||||
s, err := newTestGOAWAYServer()
|
s, err := newTestGOAWAYServer()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to set-up test GOAWAY http server, err: %v", err)
|
t.Fatalf("failed to set-up test GOAWAY http server, err: %v", err)
|
||||||
|
Loading…
Reference in New Issue
Block a user