mirror of
https://github.com/XTLS/Xray-core.git
synced 2026-11-26 03:21:43 +00:00
https://github.com/XTLS/Xray-core/pull/7463#issuecomment-7081595080 https://github.com/XTLS/Xray-core/pull/7470#issuecomment-7131388265 https://github.com/XTLS/Xray-core/pull/7470#issuecomment-7163168321 --------- Co-authored-by: StarProxima <34741787+StarProxima@users.noreply.github.com>
37 lines
668 B
Go
37 lines
668 B
Go
package task_test
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/xtls/xray-core/common"
|
|
. "github.com/xtls/xray-core/common/task"
|
|
)
|
|
|
|
func TestPeriodicTaskStop(t *testing.T) {
|
|
value := 0
|
|
task := &Periodic{
|
|
Interval: time.Second * 2,
|
|
Execute: func() error {
|
|
value++
|
|
return nil
|
|
},
|
|
}
|
|
common.Must(task.Start())
|
|
time.Sleep(time.Second * 5)
|
|
common.Must(task.Close())
|
|
if value != 2 {
|
|
t.Fatal("expected 2, but got ", value)
|
|
}
|
|
time.Sleep(time.Second * 4)
|
|
if value != 2 {
|
|
t.Fatal("expected 2, but got ", value)
|
|
}
|
|
common.Must(task.Start())
|
|
time.Sleep(time.Second * 3)
|
|
if value != 3 {
|
|
t.Fatal("Expected 3, but ", value)
|
|
}
|
|
common.Must(task.Close())
|
|
}
|