Skip to content

Commit

Permalink
Merge pull request #1215 from wzshiming/flake/test
Browse files Browse the repository at this point in the history
Fix flake test
  • Loading branch information
wzshiming authored Sep 3, 2024
2 parents f840dce + dcefd8a commit e8bb6fe
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
7 changes: 3 additions & 4 deletions test/e2e/benchmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,12 @@ func waitResource(ctx context.Context, t *testing.T, kwokctlPath, name, resource
if got == want {
return nil
}
if got == prev {
t.Logf("Error %s %d not changed\n", resource, got)
all := strings.Count(raw, "\n")
t.Logf("%s %d/%d => %d\n", resource, got, all, want)
if prev != 0 && got == prev {
return fmt.Errorf("resource %s not changed", resource)
}
prev = got
all := strings.Count(raw, "\n")
t.Logf("%s %d/%d => %d\n", resource, got, all, want)
if gap != 0 && got != 0 && (all-got) > gap {
if tolerance > 0 {
t.Logf("Error %s gap too large, actual: %d, expected: %d, retrying...\n", resource, all-got, gap)
Expand Down
25 changes: 20 additions & 5 deletions test/e2e/workable.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ import (
"runtime"
"strings"
"testing"
"time"

"sigs.k8s.io/e2e-framework/klient/wait"
"sigs.k8s.io/e2e-framework/pkg/envconf"
"sigs.k8s.io/e2e-framework/pkg/features"
)
Expand All @@ -49,14 +51,27 @@ func testWorkable(ctx context.Context, kwokctlPath, name string) error {
if err != nil {
return fmt.Errorf("failed to scale pod: %w", err)
}
output, err := exec.CommandContext(ctx, kwokctlPath, "--name", name, "kubectl", "get", "pod").Output()

err = wait.For(
func(ctx context.Context) (done bool, err error) {
output, err := exec.CommandContext(ctx, kwokctlPath, "--name", name, "kubectl", "get", "pod").Output()
if err != nil {
return false, err
}
// TODO: Use json output instead and check that node and pod work as expected
if !strings.Contains(string(output), "Running") {
return false, fmt.Errorf("pod not running")
}

return true, nil
},
wait.WithContext(ctx),
wait.WithTimeout(10*time.Second),
)
if err != nil {
return err
}
// TODO: Use json output instead and check that node and pod work as expected
if !strings.Contains(string(output), "Running") {
return fmt.Errorf("pod not running")
}

return nil
}

Expand Down

0 comments on commit e8bb6fe

Please sign in to comment.