mirror of
https://github.com/fatedier/frp.git
synced 2026-03-19 00:09:14 +08:00
test/e2e: replace sleeps with event-driven waits in chaos/group/store tests (#5231)
* test/e2e: replace sleeps with event-driven waits in chaos/group/store tests Replace 21 time.Sleep calls with deterministic waiting using WaitForOutput, WaitForTCPReady, and a new WaitForTCPUnreachable helper. Add CountOutput method for snapshot-based incremental log matching. * test/e2e: validate interval and cap dial/sleep to remaining deadline in WaitForTCPUnreachable
This commit is contained in:
@@ -144,6 +144,30 @@ func waitForClientProxyReady(configPath string, p *process.Process, timeout time
|
||||
return true
|
||||
}
|
||||
|
||||
// WaitForTCPUnreachable polls a TCP address until a connection fails or timeout.
|
||||
func WaitForTCPUnreachable(addr string, interval, timeout time.Duration) error {
|
||||
if interval <= 0 {
|
||||
return fmt.Errorf("invalid interval for TCP unreachable on %s: interval must be positive", addr)
|
||||
}
|
||||
if timeout <= 0 {
|
||||
return fmt.Errorf("invalid timeout for TCP unreachable on %s: timeout must be positive", addr)
|
||||
}
|
||||
deadline := time.Now().Add(timeout)
|
||||
for {
|
||||
remaining := time.Until(deadline)
|
||||
if remaining <= 0 {
|
||||
return fmt.Errorf("timeout waiting for TCP unreachable on %s", addr)
|
||||
}
|
||||
dialTimeout := min(interval, remaining)
|
||||
conn, err := net.DialTimeout("tcp", addr, dialTimeout)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
conn.Close()
|
||||
time.Sleep(min(interval, time.Until(deadline)))
|
||||
}
|
||||
}
|
||||
|
||||
// WaitForTCPReady polls a TCP address until a connection succeeds or timeout.
|
||||
func WaitForTCPReady(addr string, timeout time.Duration) error {
|
||||
if timeout <= 0 {
|
||||
|
||||
Reference in New Issue
Block a user