Fix flaky TestHealthCheckProcessKilled on Windows

The probe echoes to stdout and then sleeps. The test gives it a 50ms
timeout and asserts that the timeout message carries the echoed output.

The 50ms clock starts when the exec request is accepted, not when the
probe process is running. On Windows the process still has to be
scheduled, sh has to initialize, echo has to run, and the bytes have to
reach the daemon. That often exceeds 50ms, so the probe is killed having
written nothing and the daemon reports the timeout without any output.
The assertion then fails on the missing "logs1 logs2 logs3".

Raise the Windows probe timeout to 500ms and leave Linux at 50ms,
following the same reasoning as TestHealthStartInterval in this file.

Measured on a Windows daemon built from master, Hyper-V isolation,
servercore ltsc2022, 30 iterations per value:

  50ms:   14/30 failed
  200ms:   0/30 failed
  500ms:   0/30 failed
  2s:      0/30 failed

Linux, 5 iterations: unchanged, all pass in about 1s.

Signed-off-by: Srijan Keshri <srijankeshri007@gmail.com>
This commit is contained in:
Srijan Keshri
2026-08-06 12:16:36 +05:30
parent 6a43e3d5af
commit 104cdd47a6

View File

@@ -100,15 +100,24 @@ func TestHealthCheckProcessKilled(t *testing.T) {
ctx := setupTest(t)
apiClient := testEnv.APIClient()
// Note: Windows is much slower than Linux at getting the probe process to
// the point where it has written to stdout. With a 50ms timeout the probe
// is regularly killed before it has written anything, leaving the timeout
// message with no output to report.
probeTimeout := 50 * time.Millisecond
if testEnv.DaemonInfo.OSType == "windows" {
probeTimeout = 500 * time.Millisecond
}
cID := container.Run(ctx, t, apiClient, func(c *container.TestContainerConfig) {
c.Config.Healthcheck = &containertypes.HealthConfig{
Test: []string{"CMD", "sh", "-c", `echo "logs1 logs2 logs3"; sleep 60`},
Interval: 100 * time.Millisecond,
Timeout: 50 * time.Millisecond,
Timeout: probeTimeout,
Retries: 1,
}
})
poll.WaitOn(t, pollForHealthCheckLog(ctx, apiClient, cID, "Health check exceeded timeout (50ms): logs1 logs2 logs3\n"))
poll.WaitOn(t, pollForHealthCheckLog(ctx, apiClient, cID, fmt.Sprintf("Health check exceeded timeout (%v): logs1 logs2 logs3\n", probeTimeout)))
}
func TestHealthStartInterval(t *testing.T) {