mirror of
https://github.com/v2fly/v2ray-core.git
synced 2026-01-05 16:55:27 -05:00
remove dep on assert lib
This commit is contained in:
@@ -7,49 +7,54 @@ import (
|
||||
"time"
|
||||
|
||||
. "v2ray.com/core/common/signal"
|
||||
. "v2ray.com/ext/assert"
|
||||
)
|
||||
|
||||
func TestActivityTimer(t *testing.T) {
|
||||
assert := With(t)
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
timer := CancelAfterInactivity(ctx, cancel, time.Second*4)
|
||||
time.Sleep(time.Second * 6)
|
||||
assert(ctx.Err(), IsNotNil)
|
||||
if ctx.Err() == nil {
|
||||
t.Error("expected some error, but got nil")
|
||||
}
|
||||
runtime.KeepAlive(timer)
|
||||
}
|
||||
|
||||
func TestActivityTimerUpdate(t *testing.T) {
|
||||
assert := With(t)
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
timer := CancelAfterInactivity(ctx, cancel, time.Second*10)
|
||||
time.Sleep(time.Second * 3)
|
||||
assert(ctx.Err(), IsNil)
|
||||
if ctx.Err() != nil {
|
||||
t.Error("expected nil, but got ", ctx.Err().Error())
|
||||
}
|
||||
timer.SetTimeout(time.Second * 1)
|
||||
time.Sleep(time.Second * 2)
|
||||
assert(ctx.Err(), IsNotNil)
|
||||
if ctx.Err() == nil {
|
||||
t.Error("expcted some error, but got nil")
|
||||
}
|
||||
runtime.KeepAlive(timer)
|
||||
}
|
||||
|
||||
func TestActivityTimerNonBlocking(t *testing.T) {
|
||||
assert := With(t)
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
timer := CancelAfterInactivity(ctx, cancel, 0)
|
||||
time.Sleep(time.Second * 1)
|
||||
assert(ctx, HasDone)
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
default:
|
||||
t.Error("context not done")
|
||||
}
|
||||
timer.SetTimeout(0)
|
||||
timer.SetTimeout(1)
|
||||
timer.SetTimeout(2)
|
||||
}
|
||||
|
||||
func TestActivityTimerZeroTimeout(t *testing.T) {
|
||||
assert := With(t)
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
timer := CancelAfterInactivity(ctx, cancel, 0)
|
||||
assert(ctx, HasDone)
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
default:
|
||||
t.Error("context not done")
|
||||
}
|
||||
runtime.KeepAlive(timer)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user