1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-22 18:17:52 -05:00
v2fly/common/task/periodic_test.go

31 lines
483 B
Go
Raw Normal View History

2018-05-27 07:02:29 -04:00
package task_test
2018-02-08 10:19:43 -05:00
import (
"testing"
"time"
2018-05-27 07:02:29 -04:00
. "v2ray.com/core/common/task"
2018-02-08 10:19:43 -05:00
. "v2ray.com/ext/assert"
2018-05-27 07:02:29 -04:00
"v2ray.com/core/common"
2018-02-08 10:19:43 -05:00
)
func TestPeriodicTaskStop(t *testing.T) {
assert := With(t)
value := 0
2018-05-27 07:02:29 -04:00
task := &Periodic{
2018-02-08 10:19:43 -05:00
Interval: time.Second * 2,
Execute: func() error {
value++
return nil
},
}
common.Must(task.Start())
time.Sleep(time.Second * 5)
common.Must(task.Close())
assert(value, Equals, 3)
time.Sleep(time.Second * 4)
assert(value, Equals, 3)
}