Improve readability of test failures (#386)
This commit is contained in:
@@ -4,26 +4,24 @@ 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)
|
||||
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: " + description)
|
||||
return false
|
||||
t.Fatal("timed out: " + lastErr)
|
||||
case <-time.After(10 * time.Millisecond):
|
||||
if f() {
|
||||
return true
|
||||
lastErr = f()
|
||||
if lastErr == "" {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user