From 9dbcde7f31a57cf76a1c9c46d192f41ff394d137 Mon Sep 17 00:00:00 2001 From: "denis.bilenko" Date: Fri, 20 Nov 2026 08:09:46 +0000 Subject: [PATCH] Fix flaky TestIsViteReady/vite_is_running Poll isViteReady on a free port instead of a single 100ms dial on 5173. Co-authored-by: Isaac --- cmd/apps/dev_test.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/cmd/apps/dev_test.go b/cmd/apps/dev_test.go index a1e8deef447..141ba1a77ab 100644 --- a/cmd/apps/dev_test.go +++ b/cmd/apps/dev_test.go @@ -20,12 +20,11 @@ func TestIsViteReady(t *testing.T) { }) t.Run("vite is running", func(t *testing.T) { - // Start a mock server on the Vite port - listener, err := net.Listen("tcp", "localhost:5173") + // Use a free port so the check cannot collide with anything else bound to 5173. + listener, err := net.Listen("tcp", "localhost:0") require.NoError(t, err) defer listener.Close() - // Accept connections in the background go func() { for { conn, err := listener.Accept() @@ -36,11 +35,12 @@ func TestIsViteReady(t *testing.T) { } }() - // Give the listener a moment to start - time.Sleep(50 * time.Millisecond) - - ready := isViteReady(5173) - assert.True(t, ready) + // A single dial has only viteReadyCheckInterval (100ms) to succeed. On loaded + // CI runners, and on Windows where dialing "localhost" may first try an + // unbound ::1 before 127.0.0.1, one attempt can time out. Poll like the + // production wait loop does. + port := listener.Addr().(*net.TCPAddr).Port + assert.Eventually(t, func() bool { return isViteReady(port) }, 10*time.Second, 50*time.Millisecond) }) }