Skip to content

Commit 12b26bb

Browse files
authored
test: retry TestWasm when Chrome does not start in time (#584)
TestWasm failed with "websocket url timeout reached" when Chrome took more than 20s to print its DevTools address. On 20 fresh GitHub runners the first Chrome start took 5.2s to 27.4s, and 3 took over 20s. Later starts took at most 1.2s. TestWasm now retries on that error, up to 3 attempts.
1 parent 5d0eacc commit 12b26bb

1 file changed

Lines changed: 17 additions & 7 deletions

File tree

‎conn_test.go‎

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -459,15 +459,25 @@ func TestWasm(t *testing.T) {
459459
}))
460460
defer s.Close()
461461

462-
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
462+
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Minute)
463463
defer cancel()
464464

465-
cmd := exec.CommandContext(ctx, "go", "test", "-exec=wasmbrowsertest", ".", "-v")
466-
cmd.Env = append(cleanEnv(os.Environ()), "GOOS=js", "GOARCH=wasm", fmt.Sprintf("WS_ECHO_SERVER_URL=%v", s.URL))
467-
468-
b, err := cmd.CombinedOutput()
469-
if err != nil {
470-
t.Fatalf("wasm test binary failed: %v:\n%s", err, b)
465+
// Chrome's first start on a fresh CI runner can exceed the 20s that
466+
// wasmbrowsertest allows. No wasm test has run by then, so retrying is safe.
467+
const chromeStartTimeout = "websocket url timeout reached"
468+
const attempts = 3
469+
for attempt := 1; attempt <= attempts; attempt++ {
470+
cmd := exec.CommandContext(ctx, "go", "test", "-exec=wasmbrowsertest", ".", "-v")
471+
cmd.Env = append(cleanEnv(os.Environ()), "GOOS=js", "GOARCH=wasm", fmt.Sprintf("WS_ECHO_SERVER_URL=%v", s.URL))
472+
473+
b, err := cmd.CombinedOutput()
474+
if err == nil {
475+
return
476+
}
477+
if attempt == attempts || ctx.Err() != nil || !bytes.Contains(b, []byte(chromeStartTimeout)) {
478+
t.Fatalf("wasm test binary failed: %v:\n%s", err, b)
479+
}
480+
t.Logf("attempt %d/%d: Chrome did not start in time, retrying", attempt, attempts)
471481
}
472482
}
473483

0 commit comments

Comments
 (0)