Files
livekit/pkg/testutils/timeout.go
Artur Shellunts 4915692f7c Refactor getConfigString (#133)
* Add test for getConfigString

* Refactor getConfigString

* Increase connect timeout in tests
2021-10-04 17:20:47 -07:00

32 lines
556 B
Go

package testutils
import (
"context"
"testing"
"time"
"github.com/livekit/protocol/logger"
)
var (
SyncDelay = 100 * time.Millisecond
ConnectTimeout = 10 * 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
}
}
}
}