test: add waitFor helper for event-driven testing
- 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>
This commit is contained in:
File diff suppressed because one or more lines are too long
20
cmd/bd/test_wait_helper.go
Normal file
20
cmd/bd/test_wait_helper.go
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
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)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user