mirror of
https://github.com/livekit/livekit.git
synced 2026-03-30 17:45:40 +00:00
29 lines
443 B
Go
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
|
|
}
|
|
}
|
|
}
|
|
}
|