Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix flaky exec/portforward tests #4678

Merged
merged 1 commit into from
Feb 20, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 4 additions & 12 deletions pkg/client/portforward/portforward_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,11 +261,7 @@ func TestForwardPorts(t *testing.T) {
go func() {
doneChan <- pf.ForwardPorts()
}()
select {
case <-pf.Ready:
case <-time.After(500 * time.Millisecond):
t.Fatalf("%d: timed out waiting for listeners", i)
}
<-pf.Ready

conn := testCase.Upgrader.conn

Expand Down Expand Up @@ -301,13 +297,9 @@ func TestForwardPorts(t *testing.T) {
close(stopChan)

// wait for r.ForwardPorts to actually return
select {
case err := <-doneChan:
if err != nil {
t.Fatalf("%d: unexpected error: %s", err)
}
case <-time.After(200 * time.Millisecond):
t.Fatalf("%d: timeout waiting for ForwardPorts to finish")
err = <-doneChan
if err != nil {
t.Fatalf("%d: unexpected error: %s", err)
}

if e, a := len(testCase.Send), len(conn.streams); e != a {
Expand Down
62 changes: 7 additions & 55 deletions pkg/kubelet/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -569,17 +569,6 @@ func TestServeExecInContainerIdleTimeout(t *testing.T) {
return 100 * time.Millisecond
}

idleSuccess := make(chan struct{})

fw.fakeKubelet.execFunc = func(podFullName string, uid types.UID, containerName string, cmd []string, in io.Reader, out, stderr io.WriteCloser, tty bool) error {
select {
case <-idleSuccess:
case <-time.After(150 * time.Millisecond):
t.Fatalf("execFunc timed out waiting for idle timeout")
}
return nil
}

podNamespace := "other"
podName := "foo"
expectedContainerName := "baz"
Expand All @@ -605,19 +594,14 @@ func TestServeExecInContainerIdleTimeout(t *testing.T) {
defer conn.Close()

h := http.Header{}
h.Set("type", "input")
h.Set(api.StreamType, api.StreamTypeError)
stream, err := conn.CreateStream(h)
if err != nil {
t.Fatalf("error creating input stream: %v", err)
}
defer stream.Reset()

select {
case <-conn.CloseChan():
close(idleSuccess)
case <-time.After(150 * time.Millisecond):
t.Fatalf("Timed out waiting for connection closure due to idle timeout")
}
<-conn.CloseChan()
}

func TestServeExecInContainer(t *testing.T) {
Expand Down Expand Up @@ -698,11 +682,7 @@ func TestServeExecInContainer(t *testing.T) {
t.Fatalf("%d:, error writing to stdout: %v", i, err)
}
out.Close()
select {
case <-clientStdoutReadDone:
case <-time.After(10 * time.Millisecond):
t.Fatalf("%d: timed out waiting for client to read stdout", i)
}
<-clientStdoutReadDone
} else if out != nil {
t.Fatalf("%d: stdout: expected nil: %#v", i, out)
}
Expand All @@ -720,11 +700,7 @@ func TestServeExecInContainer(t *testing.T) {
t.Fatalf("%d:, error writing to stderr: %v", i, err)
}
stderr.Close()
select {
case <-clientStderrReadDone:
case <-time.After(10 * time.Millisecond):
t.Fatalf("%d: timed out waiting for client to read stderr", i)
}
<-clientStderrReadDone
} else if stderr != nil {
t.Fatalf("%d: stderr: expected nil: %#v", i, stderr)
}
Expand Down Expand Up @@ -858,11 +834,7 @@ func TestServeExecInContainer(t *testing.T) {
}
}

select {
case <-execFuncDone:
case <-time.After(10 * time.Millisecond):
t.Fatalf("%d: timed out waiting for execFunc to complete", i)
}
<-execFuncDone
}
}

Expand All @@ -873,17 +845,6 @@ func TestServePortForwardIdleTimeout(t *testing.T) {
return 100 * time.Millisecond
}

idleSuccess := make(chan struct{})

fw.fakeKubelet.portForwardFunc = func(name string, uid types.UID, port uint16, stream io.ReadWriteCloser) error {
select {
case <-idleSuccess:
case <-time.After(150 * time.Millisecond):
t.Fatalf("execFunc timed out waiting for idle timeout")
}
return nil
}

podNamespace := "other"
podName := "foo"

Expand All @@ -907,12 +868,7 @@ func TestServePortForwardIdleTimeout(t *testing.T) {
}
defer conn.Close()

select {
case <-conn.CloseChan():
close(idleSuccess)
case <-time.After(150 * time.Millisecond):
t.Fatalf("Timed out waiting for connection closure due to idle timeout")
}
<-conn.CloseChan()
}

func TestServePortForward(t *testing.T) {
Expand Down Expand Up @@ -1054,10 +1010,6 @@ func TestServePortForward(t *testing.T) {
}
}

select {
case <-portForwardFuncDone:
case <-time.After(100 * time.Millisecond):
t.Fatalf("%d: timed out waiting for portForwardFuncDone", i)
}
<-portForwardFuncDone
}
}