Files
livekit/pkg/testutils/timeout.go
Raja Subramanian e504b6678c Deficient state handling when a track needs a change (#261)
* WIP commit

* deficient handling

* Add missing ProvisionalAllocatePrepare

* adjust state on track removal

* Increase test timeout

* - Add comments about cooperative routines
- Take down transition if available in cooperative scheme
- Use layer comparison when taking down transition. Because of when the
  bitrate is measured, it is not always guaranteed bandwidthDelta is -ve
  when moving down.
- Do not add track to stream allocator till bind.

* make comment better

* a bit more clear comments

* Use OnBind on subscribed track
2021-12-16 10:58:34 +05:30

32 lines
556 B
Go

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