Fix race condition with Transport negotiations

This commit is contained in:
David Zhao
2021-06-04 12:26:23 -07:00
parent bf281b1994
commit c510ea2e1a
8 changed files with 78 additions and 55 deletions

30
pkg/testutils/timeout.go Normal file
View File

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