From ada5c46c6314f6a555cef7eb081fdb78f1e68ac1 Mon Sep 17 00:00:00 2001 From: Samuel K Date: Sun, 25 Oct 2026 10:30:15 -0600 Subject: [PATCH 1/2] fix(ci): annotate Windows podman start hangs with diagnostics --- hack/podman_ci/config.go | 11 +-- hack/podman_ci/hang_report.go | 58 +++++++++++++ hack/podman_ci/hang_report_test.go | 95 +++++++++++++++++++++ hack/podman_ci/setup.go | 15 +++- hack/podman_ci/setup_windows.go | 118 ++++++++++++++++++++------- hack/podman_ci/setup_windows_test.go | 92 ++++++++++++++++++++- 6 files changed, 349 insertions(+), 40 deletions(-) create mode 100644 hack/podman_ci/hang_report.go create mode 100644 hack/podman_ci/hang_report_test.go diff --git a/hack/podman_ci/config.go b/hack/podman_ci/config.go index f5810a379e..fcc6b55cbb 100644 --- a/hack/podman_ci/config.go +++ b/hack/podman_ci/config.go @@ -21,11 +21,12 @@ const ( ) type SetupConfig struct { - Mode Mode - PodmanPath string - CrunPath string - BootstrapTimeout time.Duration - GitHubEnvPath string + Mode Mode + PodmanPath string + CrunPath string + BootstrapTimeout time.Duration + GitHubEnvPath string + GitHubStepSummaryPath string } func validateConfig(cfg SetupConfig, goos string) error { diff --git a/hack/podman_ci/hang_report.go b/hack/podman_ci/hang_report.go new file mode 100644 index 0000000000..b51803ce6f --- /dev/null +++ b/hack/podman_ci/hang_report.go @@ -0,0 +1,58 @@ +package main + +import ( + "fmt" + "strings" +) + +const maxStepSummaryDetailBytes = 32 << 10 + +var ( + workflowDataEscaper = strings.NewReplacer("%", "%25", "\r", "%0D", "\n", "%0A") + workflowPropertyEscaper = strings.NewReplacer( + "%", "%25", "\r", "%0D", "\n", "%0A", ":", "%3A", ",", "%2C", + ) +) + +// hangReporter leaves evidence of a setup hang in the step output (a GitHub +// warning annotation) and in the job step summary. +type hangReporter struct { + log *Logger + files FileSystem + summaryPath string +} + +func (r hangReporter) Report(title, message, details string) { + r.log.Printf( + "::warning title=%s::%s", + workflowPropertyEscaper.Replace(title), + workflowDataEscaper.Replace(message), + ) + r.appendSummary(title, message, details) +} + +func (r hangReporter) appendSummary(title, message, details string) { + if r.summaryPath == "" || r.files == nil { + return + } + out, err := r.files.OpenAppend(r.summaryPath) + if err != nil { + r.log.Printf("[podman-windows] step summary unavailable: %v", err) + return + } + defer func() { _ = out.Close() }() + _, _ = fmt.Fprintf( + out, + "### %s\n\n%s\n\n```\n%s\n```\n", + title, + message, + tailBytes(details, maxStepSummaryDetailBytes), + ) +} + +func tailBytes(text string, limit int) string { + if len(text) <= limit { + return text + } + return strings.ToValidUTF8(text[len(text)-limit:], "") +} diff --git a/hack/podman_ci/hang_report_test.go b/hack/podman_ci/hang_report_test.go new file mode 100644 index 0000000000..ce200753e5 --- /dev/null +++ b/hack/podman_ci/hang_report_test.go @@ -0,0 +1,95 @@ +package main + +import ( + "bytes" + "errors" + "io" + "strings" + "testing" +) + +const testSummaryPath = "summary.md" + +type summaryFS struct { + FileSystem + appended map[string]*summaryFile + openErr error +} + +type summaryFile struct{ bytes.Buffer } + +func (*summaryFile) Close() error { return nil } + +func (f *summaryFS) OpenAppend(path string) (io.WriteCloser, error) { + if f.openErr != nil { + return nil, f.openErr + } + if f.appended == nil { + f.appended = map[string]*summaryFile{} + } + file := &summaryFile{} + f.appended[path] = file + return file, nil +} + +func TestHangReporterWritesEscapedAnnotationAndSummary(t *testing.T) { + var out bytes.Buffer + files := &summaryFS{} + reporter := hangReporter{ + log: &Logger{Out: &out}, + files: files, + summaryPath: testSummaryPath, + } + + reporter.Report("title: a,b", "100%\nsecond line", "diagnostic output") + + wantAnnotation := "::warning title=title%3A a%2Cb::100%25%0Asecond line\n" + if out.String() != wantAnnotation { + t.Fatalf("annotation = %q, want %q", out.String(), wantAnnotation) + } + summary := files.appended[testSummaryPath].String() + for _, want := range []string{"### title: a,b", "100%\nsecond line", "diagnostic output"} { + if !strings.Contains(summary, want) { + t.Fatalf("summary missing %q: %s", want, summary) + } + } +} + +func TestHangReporterTruncatesSummaryDetailsKeepingTail(t *testing.T) { + files := &summaryFS{} + reporter := hangReporter{log: &Logger{Out: io.Discard}, files: files, summaryPath: "s.md"} + details := "HEAD" + strings.Repeat("x", maxStepSummaryDetailBytes) + "TAIL" + + reporter.Report("title", "message", details) + + summary := files.appended["s.md"].String() + if strings.Contains(summary, "HEAD") || !strings.Contains(summary, "TAIL") { + t.Fatalf("summary did not keep the tail of the details: %.80s", summary) + } +} + +func TestHangReporterSummaryFailureDoesNotHideAnnotation(t *testing.T) { + var out bytes.Buffer + reporter := hangReporter{ + log: &Logger{Out: &out}, + files: &summaryFS{openErr: errors.New("read-only")}, + summaryPath: testSummaryPath, + } + + reporter.Report("title", "message", "details") + + if !strings.Contains(out.String(), "::warning title=title::message") || + !strings.Contains(out.String(), "step summary unavailable: read-only") { + t.Fatalf("output = %q", out.String()) + } +} + +func TestHangReporterWithoutSummaryPathOnlyAnnotates(t *testing.T) { + files := &summaryFS{} + var out bytes.Buffer + hangReporter{log: &Logger{Out: &out}, files: files}.Report("title", "message", "details") + + if len(files.appended) != 0 || !strings.Contains(out.String(), "::warning") { + t.Fatalf("appended=%v output=%q", files.appended, out.String()) + } +} diff --git a/hack/podman_ci/setup.go b/hack/podman_ci/setup.go index c888486032..6b45324b22 100644 --- a/hack/podman_ci/setup.go +++ b/hack/podman_ci/setup.go @@ -50,10 +50,11 @@ func newRootCommand() *cobra.Command { func newSetupCommand() *cobra.Command { cfg := SetupConfig{ - PodmanPath: platformDefaultPodmanPath(), - CrunPath: "/usr/local/bin/crun", - BootstrapTimeout: 270 * time.Second, - GitHubEnvPath: os.Getenv("GITHUB_ENV"), + PodmanPath: platformDefaultPodmanPath(), + CrunPath: "/usr/local/bin/crun", + BootstrapTimeout: 270 * time.Second, + GitHubEnvPath: os.Getenv("GITHUB_ENV"), + GitHubStepSummaryPath: os.Getenv("GITHUB_STEP_SUMMARY"), } cmd := &cobra.Command{ Use: "setup", Short: "Configure and validate a Podman CI runtime", Args: cobra.NoArgs, @@ -75,6 +76,12 @@ func newSetupCommand() *cobra.Command { DurationVar(&cfg.BootstrapTimeout, "bootstrap-timeout", cfg.BootstrapTimeout, "maximum bootstrap duration") cmd.Flags(). StringVar(&cfg.GitHubEnvPath, "github-env", cfg.GitHubEnvPath, "GitHub Actions environment file") + cmd.Flags().StringVar( + &cfg.GitHubStepSummaryPath, + "github-step-summary", + cfg.GitHubStepSummaryPath, + "GitHub Actions step summary file", + ) cmd.Flags().Var(newModeValue(&cfg.Mode), "mode", "Podman mode: rootless or rootful") _ = cmd.MarkFlagRequired("mode") return cmd diff --git a/hack/podman_ci/setup_windows.go b/hack/podman_ci/setup_windows.go index 5a029bf022..a8f4866fa8 100644 --- a/hack/podman_ci/setup_windows.go +++ b/hack/podman_ci/setup_windows.go @@ -4,6 +4,7 @@ package main import ( "context" + "errors" "fmt" "os" "strings" @@ -31,20 +32,35 @@ const ( windowsHardDeadlinePadding = 10 * time.Second windowsHardDeadlineDiagnosticsGrace = 2 * time.Second maxTransientPullRetries = 2 + windowsHangTitle = "Windows podman start hang" ) func platformSetup(ctx context.Context, deps Dependencies, cfg SetupConfig) error { - watchdog := armWatchdog(cfg.BootstrapTimeout+windowsHardDeadlinePadding, deps.Log) + watchdog := armWatchdog( + cfg.BootstrapTimeout+windowsHardDeadlinePadding, + deps.Log, + windowsHangReporter(deps, cfg), + ) defer watchdog.Stop() return setupWindows(ctx, deps, cfg) } +func windowsHangReporter(deps Dependencies, cfg SetupConfig) hangReporter { + return hangReporter{log: deps.Log, files: deps.Files, summaryPath: cfg.GitHubStepSummaryPath} +} + func setupWindows(ctx context.Context, deps Dependencies, cfg SetupConfig) error { budget, err := NewBudget(cfg.BootstrapTimeout, deps.Clock) if err != nil { return err } - state := &windowsSetup{ctx: ctx, deps: deps, budget: budget, cfg: cfg} + state := &windowsSetup{ + ctx: ctx, + deps: deps, + budget: budget, + cfg: cfg, + report: windowsHangReporter(deps, cfg), + } runErr := state.run() if runErr != nil { // Per-command timeouts deliberately leave descendants (podman, @@ -63,6 +79,7 @@ type windowsSetup struct { deps Dependencies budget *Budget cfg SetupConfig + report hangReporter } func (s *windowsSetup) run() error { @@ -99,7 +116,8 @@ func (s *windowsSetup) handleAttemptFailure(attempt int, failure error) error { if canRecover { reserve = windowsDiagnosticReserve } - s.writeDiagnostics(reserve) + diagnostics := s.writeDiagnostics(reserve) + s.reportHang(failure, diagnostics) if !canRecover || s.budget.Remaining(windowsDiagnosticReserve) < windowsMinimumRecoveryTime { if canRecover { s.writeDiagnostics(0) @@ -137,11 +155,11 @@ func (s *windowsSetup) initializeMachine(attempt int) error { return err } if result.TimedOut { - return fmt.Errorf( - "PODMAN_WINDOWS_MACHINE_INIT_TIMEOUT attempt=%d %s", - attempt, - describeCommand(s.cfg.PodmanPath, args, result), - ) + return &hangError{ + code: "PODMAN_WINDOWS_MACHINE_INIT_TIMEOUT", + attempt: attempt, + detail: describeCommand(s.cfg.PodmanPath, args, result), + } } if result.Success() { return nil @@ -258,11 +276,11 @@ func (s *windowsSetup) startAndWait(attempt int) error { windowsDiagnosticReserve, ) if result.TimedOut { - return fmt.Errorf( - "PODMAN_WINDOWS_MACHINE_START_TIMEOUT attempt=%d %s", - attempt, - describeCommand(s.cfg.PodmanPath, args, result), - ) + return &hangError{ + code: "PODMAN_WINDOWS_MACHINE_START_TIMEOUT", + attempt: attempt, + detail: describeCommand(s.cfg.PodmanPath, args, result), + } } if !result.Success() { return fmt.Errorf( @@ -298,11 +316,11 @@ func (s *windowsSetup) waitForReady(attempt int) error { ) s.deps.Clock.Sleep(sleep) } - return fmt.Errorf( - "PODMAN_WINDOWS_READINESS_TIMEOUT attempt=%d last=%s", - attempt, - describeCommand(s.cfg.PodmanPath, []string{"info"}, last), - ) + return &hangError{ + code: "PODMAN_WINDOWS_READINESS_TIMEOUT", + attempt: attempt, + detail: "last=" + describeCommand(s.cfg.PodmanPath, []string{"info"}, last), + } } func (s *windowsSetup) recover(failure error) error { @@ -390,7 +408,7 @@ func (s *windowsSetup) runCommand(spec CommandSpec, reserve time.Duration) Comma return result } -func (s *windowsSetup) writeDiagnostics(reserve time.Duration) { +func (s *windowsSetup) writeDiagnostics(reserve time.Duration) string { commands := []CommandSpec{ {Path: s.cfg.PodmanPath, Args: []string{"version"}, Timeout: 3 * time.Second}, {Path: s.cfg.PodmanPath, Args: []string{commandMachine, "list"}, Timeout: 3 * time.Second}, @@ -407,23 +425,51 @@ func (s *windowsSetup) writeDiagnostics(reserve time.Duration) { {Path: commandWSL, Args: []string{"--status"}, Timeout: 3 * time.Second}, {Path: commandWSL, Args: []string{"-l", "-v"}, Timeout: 3 * time.Second}, } + var collected strings.Builder + record := func(line string) { + s.deps.Log.Printf("[podman-windows] %s", line) + collected.WriteString(line + "\n") + } for _, command := range commands { if s.budget.Remaining(reserve) <= 0 { break } result := s.runCommand(command, reserve) - s.deps.Log.Printf( - "[podman-windows] %s %s: exit=%s timeout=%t %s", + record(fmt.Sprintf( + "%s %s: exit=%s timeout=%t %s", command.Path, strings.Join(command.Args, " "), exitCodeString(result.ExitCode), result.TimedOut, result.Output(), - ) + )) } for _, process := range matchingWindowsProcesses() { - s.deps.Log.Printf("[podman-windows] process pid=%d name=%s", process.PID, process.Name) + record(describeProcess(process)) + } + return collected.String() +} + +func (s *windowsSetup) reportHang(failure error, diagnostics string) { + hang, ok := errors.AsType[*hangError](failure) + if !ok { + return } + s.report.Report(windowsHangTitle, hang.summary(), hang.Error()+"\n\n"+diagnostics) +} + +type hangError struct { + code string + attempt int + detail string +} + +func (e *hangError) Error() string { return e.summary() + " " + e.detail } + +func (e *hangError) summary() string { return fmt.Sprintf("%s attempt=%d", e.code, e.attempt) } + +func describeProcess(process processInfo) string { + return fmt.Sprintf("process pid=%d name=%s", process.PID, process.Name) } func describeCommand(path string, args []string, result CommandResult) string { @@ -467,7 +513,7 @@ type ( } ) -func armWatchdog(timeout time.Duration, log *Logger) watchdog { +func armWatchdog(timeout time.Duration, log *Logger, report hangReporter) watchdog { watch := &timerWatchdog{stop: make(chan struct{})} go func() { timer := time.NewTimer(timeout) @@ -480,11 +526,7 @@ func armWatchdog(timeout time.Duration, log *Logger) watchdog { done := make(chan struct{}) go func() { defer close(done) - log.Printf( - "[podman-windows] hard_deadline_exceeded timeout_ms=%d", - timeout.Milliseconds(), - ) - terminateStrayProcessesHook(log) + handleHardDeadline(timeout, log, report) }() select { case <-done: @@ -503,4 +545,22 @@ func armWatchdog(timeout time.Duration, log *Logger) watchdog { return watch } +func handleHardDeadline(timeout time.Duration, log *Logger, report hangReporter) { + log.Printf("[podman-windows] hard_deadline_exceeded timeout_ms=%d", timeout.Milliseconds()) + report.Report( + windowsHangTitle, + fmt.Sprintf("PODMAN_WINDOWS_HARD_DEADLINE timeout_ms=%d", timeout.Milliseconds()), + runningProcessesReport(), + ) + terminateStrayProcessesHook(log) +} + +func runningProcessesReport() string { + var report strings.Builder + for _, process := range matchingWindowsProcesses() { + report.WriteString(describeProcess(process) + "\n") + } + return report.String() +} + func (w *timerWatchdog) Stop() { w.once.Do(func() { close(w.stop) }) } diff --git a/hack/podman_ci/setup_windows_test.go b/hack/podman_ci/setup_windows_test.go index f9415133dc..5ada6853c0 100644 --- a/hack/podman_ci/setup_windows_test.go +++ b/hack/podman_ci/setup_windows_test.go @@ -3,6 +3,7 @@ package main import ( + "bytes" "context" "fmt" "io" @@ -325,6 +326,89 @@ func TestWindowsSecondFailedAttemptReturnsStableRecoveryMarker(t *testing.T) { } } +func TestWindowsStartHangIsAnnotatedAndRetriedOnce(t *testing.T) { + clock := &fakeClock{now: time.Unix(1, 0)} + runner := &windowsFakeRunner{ + clock: clock, + results: map[string][]CommandResult{}, + durationQueues: map[string][]time.Duration{ + testMachineStart: {windowsStartTimeout + time.Second}, + }, + } + var output bytes.Buffer + files := &summaryFS{} + deps := windowsDependencies(runner, clock) + deps.Log = &Logger{Out: &output, Err: io.Discard} + deps.Files = files + cfg := windowsConfig(t) + cfg.GitHubStepSummaryPath = testSummaryPath + + if err := setupWindows(context.Background(), deps, cfg); err != nil { + t.Fatalf("retry after hang should recover: %v", err) + } + + wantAnnotation := "::warning title=Windows podman start hang::" + + "PODMAN_WINDOWS_MACHINE_START_TIMEOUT attempt=1" + if strings.Count(output.String(), wantAnnotation) != 1 { + t.Fatalf("annotation missing or repeated: %s", output.String()) + } + summary := files.appended[testSummaryPath].String() + if !strings.Contains(summary, "machine list") || !strings.Contains(summary, "wsl.exe -l -v") { + t.Fatalf("summary lacks diagnostics: %s", summary) + } + if countWindowsCalls(runner, testMachineStart) != 2 { + t.Fatalf("start calls = %d, want 2", countWindowsCalls(runner, testMachineStart)) + } +} + +func TestWindowsSecondStartHangFailsStepWithBothAnnotations(t *testing.T) { + clock := &fakeClock{now: time.Unix(1, 0)} + hang := windowsStartTimeout + time.Second + runner := &windowsFakeRunner{ + clock: clock, + results: map[string][]CommandResult{}, + durationQueues: map[string][]time.Duration{testMachineStart: {hang, hang}}, + } + var output bytes.Buffer + deps := windowsDependencies(runner, clock) + deps.Log = &Logger{Out: &output, Err: io.Discard} + + err := setupWindows(context.Background(), deps, windowsConfig(t)) + + if err == nil || !strings.HasPrefix(err.Error(), "PODMAN_WINDOWS_RECOVERY_FAILED:") { + t.Fatalf("second hang must fail the step, got %v", err) + } + for _, attempt := range []string{"attempt=1", "attempt=2"} { + want := "::warning title=Windows podman start hang::" + + "PODMAN_WINDOWS_MACHINE_START_TIMEOUT " + attempt + if !strings.Contains(output.String(), want) { + t.Fatalf("missing annotation for %s: %s", attempt, output.String()) + } + } +} + +func TestWindowsNonHangFailureIsNotAnnotatedAsHang(t *testing.T) { + clock := &fakeClock{now: time.Unix(1, 0)} + runner := &windowsFakeRunner{ + clock: clock, + results: map[string][]CommandResult{ + testMachineStart: {failureResult("pipe busy"), failureResult("pipe busy")}, + }, + durations: map[string]time.Duration{}, + } + var output bytes.Buffer + deps := windowsDependencies(runner, clock) + deps.Log = &Logger{Out: &output, Err: io.Discard} + + if err := setupWindows(context.Background(), deps, windowsConfig(t)); err == nil { + t.Fatal("expected failure") + } + + if strings.Contains(output.String(), "::warning") { + t.Fatalf("non-timeout failure annotated as a hang: %s", output.String()) + } +} + func TestWindowsBudgetExhaustionRejectsLateSuccess(t *testing.T) { clock := &fakeClock{now: time.Unix(1, 0)} runner := &windowsFakeRunner{ @@ -388,10 +472,14 @@ func runWatchdogChild(mode string) { os.Exit(1) case <-time.After(100 * time.Millisecond): } - armWatchdog(750*time.Millisecond, &Logger{Out: io.Discard, Err: stderr}) + armWatchdog(750*time.Millisecond, &Logger{Out: io.Discard, Err: stderr}, hangReporter{}) select {} } - wd := armWatchdog(750*time.Millisecond, &Logger{Out: os.Stdout, Err: os.Stderr}) + wd := armWatchdog( + 750*time.Millisecond, + &Logger{Out: os.Stdout, Err: os.Stderr}, + hangReporter{}, + ) if mode == "complete" { wd.Stop() wd.Stop() From a8be199bf05f9fa793eda4cf95cebb6f6e33a233 Mon Sep 17 00:00:00 2001 From: Samuel K Date: Sun, 25 Oct 2026 10:33:18 -0600 Subject: [PATCH 2/2] fix(ci): classify remaining podman timeouts and decouple sweep from reporting --- hack/podman_ci/setup_windows.go | 34 ++++++++++++++++------- hack/podman_ci/setup_windows_test.go | 41 ++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 10 deletions(-) diff --git a/hack/podman_ci/setup_windows.go b/hack/podman_ci/setup_windows.go index a8f4866fa8..77392c4acb 100644 --- a/hack/podman_ci/setup_windows.go +++ b/hack/podman_ci/setup_windows.go @@ -186,11 +186,12 @@ func (s *windowsSetup) runMachineInit( for pullAttempt := 1; ; pullAttempt++ { initTimeout := s.budget.Bound(windowsInitTimeout, reserve) if initTimeout <= 0 { - return CommandResult{}, fmt.Errorf( - "PODMAN_WINDOWS_MACHINE_INIT_TIMEOUT attempt=%d output=%s", - attempt, - "PODMAN_WINDOWS_BOOTSTRAP_BUDGET_EXHAUSTED: insufficient initialization budget", - ) + return CommandResult{}, &hangError{ + code: "PODMAN_WINDOWS_MACHINE_INIT_TIMEOUT", + attempt: attempt, + detail: "output=PODMAN_WINDOWS_BOOTSTRAP_BUDGET_EXHAUSTED: " + + "insufficient initialization budget", + } } result := s.runCommand( CommandSpec{Path: s.cfg.PodmanPath, Args: args, Timeout: initTimeout}, @@ -259,6 +260,13 @@ func (s *windowsSetup) configureRootful(attempt int) error { CommandSpec{Path: s.cfg.PodmanPath, Args: args, Timeout: 20 * time.Second}, windowsDiagnosticReserve, ) + if result.TimedOut { + return &hangError{ + code: "PODMAN_WINDOWS_MACHINE_START_FAILED", + attempt: attempt, + detail: describeCommand(s.cfg.PodmanPath, args, result), + } + } if !result.Success() { return fmt.Errorf( "PODMAN_WINDOWS_MACHINE_START_FAILED attempt=%d %s", @@ -547,12 +555,18 @@ func armWatchdog(timeout time.Duration, log *Logger, report hangReporter) watchd func handleHardDeadline(timeout time.Duration, log *Logger, report hangReporter) { log.Printf("[podman-windows] hard_deadline_exceeded timeout_ms=%d", timeout.Milliseconds()) - report.Report( - windowsHangTitle, - fmt.Sprintf("PODMAN_WINDOWS_HARD_DEADLINE timeout_ms=%d", timeout.Milliseconds()), - runningProcessesReport(), - ) + processes := runningProcessesReport() + reported := make(chan struct{}) + go func() { + defer close(reported) + report.Report( + windowsHangTitle, + fmt.Sprintf("PODMAN_WINDOWS_HARD_DEADLINE timeout_ms=%d", timeout.Milliseconds()), + processes, + ) + }() terminateStrayProcessesHook(log) + <-reported } func runningProcessesReport() string { diff --git a/hack/podman_ci/setup_windows_test.go b/hack/podman_ci/setup_windows_test.go index 5ada6853c0..4aee47b810 100644 --- a/hack/podman_ci/setup_windows_test.go +++ b/hack/podman_ci/setup_windows_test.go @@ -5,6 +5,7 @@ package main import ( "bytes" "context" + "errors" "fmt" "io" "os" @@ -186,6 +187,46 @@ func TestWindowsFirstInitReservesDiagnosticsAndRecovery(t *testing.T) { } } +func TestWindowsInitBudgetExhaustionAndRootfulTimeoutAreHangs(t *testing.T) { + tests := map[string]struct { + budget time.Duration + durations map[string]time.Duration + }{ + "init budget exhausted": {budget: time.Second}, + "rootful timeout": { + budget: 270 * time.Second, + durations: map[string]time.Duration{"machine set --rootful": time.Minute}, + }, + } + for name, test := range tests { + t.Run(name, func(t *testing.T) { + clock := &fakeClock{now: time.Unix(1, 0)} + runner := &windowsFakeRunner{ + clock: clock, + results: map[string][]CommandResult{}, + durations: test.durations, + } + budget, err := NewBudget(test.budget, clock) + if err != nil { + t.Fatal(err) + } + clock.Sleep(2 * time.Second) + state := &windowsSetup{ + ctx: context.Background(), + deps: windowsDependencies(runner, clock), + budget: budget, + cfg: windowsConfig(t), + } + + err = state.startMachineAttempt(1) + + if _, ok := errors.AsType[*hangError](err); !ok { + t.Fatalf("error = %v, want a hang error", err) + } + }) + } +} + func TestWindowsPartialInitRecoveryRetriesWithFreshBudget(t *testing.T) { clock := &fakeClock{now: time.Unix(1, 0)} runner := &windowsFakeRunner{