blob: b0c91fe79b9213e93cb8f530140961e66d2b94df (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
package timeoutat
import (
"context"
"testing"
"time"
"github.com/network-quality/goresponsiveness/debug"
)
func TestTimeoutAt(t *testing.T) {
testTime := 5 * time.Second
testTimeLimit := 6 * time.Second
now := time.Now()
select {
case <-TimeoutAt(context.Background(), time.Now().Add(testTime), debug.NoDebug):
}
then := time.Now()
actualTime := then.Sub(now)
if actualTime >= testTimeLimit {
t.Fatalf("Should have taken 5 seconds but it really took %v!", actualTime)
}
}
|