timer_test.go 709 B

1234567891011121314151617181920212223242526272829303132
  1. package signal_test
  2. import (
  3. "context"
  4. "runtime"
  5. "testing"
  6. "time"
  7. . "v2ray.com/core/common/signal"
  8. "v2ray.com/core/testing/assert"
  9. )
  10. func TestActivityTimer(t *testing.T) {
  11. assert := assert.On(t)
  12. ctx, timer := CancelAfterInactivity(context.Background(), time.Second*5)
  13. time.Sleep(time.Second * 6)
  14. assert.Error(ctx.Err()).IsNotNil()
  15. runtime.KeepAlive(timer)
  16. }
  17. func TestActivityTimerUpdate(t *testing.T) {
  18. assert := assert.On(t)
  19. ctx, timer := CancelAfterInactivity(context.Background(), time.Second*10)
  20. time.Sleep(time.Second * 3)
  21. assert.Error(ctx.Err()).IsNil()
  22. timer.SetTimeout(time.Second * 1)
  23. time.Sleep(time.Second * 2)
  24. assert.Error(ctx.Err()).IsNotNil()
  25. runtime.KeepAlive(timer)
  26. }