1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-09-29 23:36:25 -04:00
v2fly/common/signal/timer_test.go

33 lines
671 B
Go
Raw Normal View History

package signal_test
import (
"context"
"runtime"
"testing"
"time"
. "v2ray.com/core/common/signal"
2017-10-24 10:15:35 -04:00
. "v2ray.com/ext/assert"
)
func TestActivityTimer(t *testing.T) {
2017-10-24 10:15:35 -04:00
assert := With(t)
ctx, timer := CancelAfterInactivity(context.Background(), time.Second*5)
time.Sleep(time.Second * 6)
2017-10-24 10:15:35 -04:00
assert(ctx.Err(), IsNotNil)
runtime.KeepAlive(timer)
}
func TestActivityTimerUpdate(t *testing.T) {
2017-10-24 10:15:35 -04:00
assert := With(t)
ctx, timer := CancelAfterInactivity(context.Background(), time.Second*10)
time.Sleep(time.Second * 3)
2017-10-24 10:15:35 -04:00
assert(ctx.Err(), IsNil)
timer.SetTimeout(time.Second * 1)
time.Sleep(time.Second * 2)
2017-10-24 10:15:35 -04:00
assert(ctx.Err(), IsNotNil)
runtime.KeepAlive(timer)
}