- Add test_wait_helper.go with waitFor() function for polling-based test assertions - Used by daemon watcher platform tests for non-blocking event verification - Sync beads.jsonl Amp-Thread-ID: https://ampcode.com/threads/T-80e427aa-40e0-48a6-82e0-e29a93edd444 Co-authored-by: Amp <amp@ampcode.com>
21 lines
446 B
Go
21 lines
446 B
Go
package main
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
// waitFor repeatedly evaluates pred until it returns true or timeout expires.
|
|
// Use this instead of time.Sleep for event-driven testing.
|
|
func waitFor(t *testing.T, timeout, poll time.Duration, pred func() bool) {
|
|
t.Helper()
|
|
deadline := time.Now().Add(timeout)
|
|
for time.Now().Before(deadline) {
|
|
if pred() {
|
|
return
|
|
}
|
|
time.Sleep(poll)
|
|
}
|
|
t.Fatalf("condition not met within %v", timeout)
|
|
}
|