test: harden weed mini readiness checks

This commit is contained in:
Chris Lu
2026-03-30 16:21:36 -07:00
parent 7d426d2a56
commit d5068b3ee6
5 changed files with 81 additions and 153 deletions

View File

@@ -2,6 +2,7 @@ package testutil
import (
"context"
"fmt"
"net"
"net/http"
"os/exec"
@@ -64,3 +65,17 @@ func WaitForService(url string, timeout time.Duration) bool {
}
}
}
func WaitForPort(port int, timeout time.Duration) bool {
deadline := time.Now().Add(timeout)
address := fmt.Sprintf("127.0.0.1:%d", port)
for time.Now().Before(deadline) {
conn, err := net.DialTimeout("tcp", address, 500*time.Millisecond)
if err == nil {
_ = conn.Close()
return true
}
time.Sleep(100 * time.Millisecond)
}
return false
}