Skip to content

Commit

Permalink
Fix TestWaitForPodSucceeded flake (#3818)
Browse files Browse the repository at this point in the history
+ Increase the timeout
+ Better error message

Signed-off-by: David Gageot <[email protected]>
  • Loading branch information
dgageot authored Mar 13, 2020
1 parent d72e304 commit 6be2fdf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 1 addition & 2 deletions pkg/skaffold/kubernetes/wait.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package kubernetes

import (
"context"
"errors"
"fmt"
"time"

Expand All @@ -43,7 +42,7 @@ func watchUntilTimeout(ctx context.Context, timeout time.Duration, w watch.Inter
for {
select {
case <-ctx.Done():
return errors.New("context closed while waiting for condition")
return ctx.Err()
case event := <-w.ResultChan():
done, err := condition(&event)
if err != nil {
Expand Down
6 changes: 5 additions & 1 deletion pkg/skaffold/kubernetes/wait_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,21 @@ func TestWaitForPodSucceeded(t *testing.T) {
tests := []struct {
description string
phases []v1.PodPhase
timeout time.Duration
shouldErr bool
}{
{
description: "pod eventually succeeds",
timeout: 1 * time.Second,
phases: []v1.PodPhase{v1.PodRunning, v1.PodSucceeded},
}, {
description: "pod eventually fails",
timeout: 1 * time.Second,
phases: []v1.PodPhase{v1.PodRunning, v1.PodFailed},
shouldErr: true,
}, {
description: "pod times out",
timeout: 10 * time.Millisecond,
phases: []v1.PodPhase{v1.PodRunning, v1.PodRunning, v1.PodRunning, v1.PodRunning, v1.PodRunning, v1.PodRunning},
shouldErr: true,
},
Expand All @@ -59,7 +63,7 @@ func TestWaitForPodSucceeded(t *testing.T) {

errChan := make(chan error)
go func() {
errChan <- WaitForPodSucceeded(context.TODO(), fakePods, "", 10*time.Millisecond)
errChan <- WaitForPodSucceeded(context.TODO(), fakePods, "", test.timeout)
}()

for _, phase := range test.phases {
Expand Down

0 comments on commit 6be2fdf

Please sign in to comment.