Files
livekit/pkg/testutils/timeout.go
David Colburn faa870de3d Move callbacks out of messageRouter (#269)
* move callbacks out of messageRouter

* OCD

* more OCD

* fix forwarder test

* even more OCD

* maximum OCD

* package name collision, copy lock by value
2021-12-17 13:19:23 -08:00

31 lines
515 B
Go

package testutils
import (
"context"
"testing"
"time"
"github.com/livekit/protocol/logger"
)
var (
ConnectTimeout = 30 * time.Second
)
func WithTimeout(t *testing.T, description string, f func() bool) bool {
logger.Infow(description)
ctx, cancel := context.WithTimeout(context.Background(), ConnectTimeout)
defer cancel()
for {
select {
case <-ctx.Done():
t.Fatal("timed out: " + description)
return false
case <-time.After(10 * time.Millisecond):
if f() {
return true
}
}
}
}