mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-31 23:37:01 +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"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"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 {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
fs := pflag.NewFlagSet("test", pflag.PanicOnError)
|
||||
@ -370,6 +380,15 @@ profiles:
|
||||
if err != nil {
|
||||
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 {
|
||||
fs.AddFlagSet(f)
|
||||
}
|
||||
@ -379,12 +398,10 @@ profiles:
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
cc, sched, err := Setup(ctx, opts)
|
||||
_, sched, err := Setup(ctx, opts)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer cc.SecureServing.Listener.Close()
|
||||
defer cc.InsecureServing.Listener.Close()
|
||||
|
||||
gotPlugins := make(map[string]map[string][]kubeschedulerconfig.Plugin)
|
||||
for n, p := range sched.Profiles {
|
||||
|
@ -61,7 +61,13 @@ func unsetEnv(key string) func() {
|
||||
|
||||
func TestHTTPProbeProxy(t *testing.T) {
|
||||
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)()
|
||||
@ -71,16 +77,6 @@ func TestHTTPProbeProxy(t *testing.T) {
|
||||
followNonLocalRedirects := true
|
||||
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
|
||||
time.Sleep(2 * time.Second)
|
||||
url, err := url.Parse("http://example.com")
|
||||
|
@ -342,6 +342,7 @@ func TestClientReceivedGOAWAY(t *testing.T) {
|
||||
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
var mu sync.Mutex
|
||||
// localAddr indicates how many TCP connection set up
|
||||
localAddr := make([]string, 0)
|
||||
|
||||
@ -350,7 +351,10 @@ func TestClientReceivedGOAWAY(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("unexpect connection err: %v", err)
|
||||
}
|
||||
|
||||
mu.Lock()
|
||||
localAddr = append(localAddr, conn.LocalAddr().String())
|
||||
mu.Unlock()
|
||||
return
|
||||
})
|
||||
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.
|
||||
// Known issues in history: https://github.com/kubernetes/kubernetes/issues/91131.
|
||||
func TestGOAWAYConcurrency(t *testing.T) {
|
||||
t.Skip("disabled because of https://github.com/kubernetes/kubernetes/issues/94532")
|
||||
|
||||
s, err := newTestGOAWAYServer()
|
||||
if err != nil {
|
||||
t.Fatalf("failed to set-up test GOAWAY http server, err: %v", err)
|
||||
|
Loading…
Reference in New Issue
Block a user