Files
livekit/pkg/testutils/timeout.go
2022-01-28 21:34:21 -08:00

29 lines
443 B
Go

package testutils
import (
"context"
"testing"
"time"
)
var (
ConnectTimeout = 30 * time.Second
)
func WithTimeout(t *testing.T, f func() string) {
ctx, cancel := context.WithTimeout(context.Background(), ConnectTimeout)
defer cancel()
lastErr := ""
for {
select {
case <-ctx.Done():
t.Fatal("timed out: " + lastErr)
case <-time.After(10 * time.Millisecond):
lastErr = f()
if lastErr == "" {
return
}
}
}
}