mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-01-02 23:47:07 -05:00
test case for periodic task
This commit is contained in:
parent
5755d4153a
commit
c368412728
29
common/signal/task_test.go
Normal file
29
common/signal/task_test.go
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
package signal_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"v2ray.com/core/common"
|
||||||
|
. "v2ray.com/core/common/signal"
|
||||||
|
. "v2ray.com/ext/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestPeriodicTaskStop(t *testing.T) {
|
||||||
|
assert := With(t)
|
||||||
|
|
||||||
|
value := 0
|
||||||
|
task := &PeriodicTask{
|
||||||
|
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)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user