From c368412728c90327ea26a68d27ff38e5ff45e09a Mon Sep 17 00:00:00 2001 From: Darien Raymond Date: Thu, 8 Feb 2018 16:19:43 +0100 Subject: [PATCH] test case for periodic task --- common/signal/task_test.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 common/signal/task_test.go diff --git a/common/signal/task_test.go b/common/signal/task_test.go new file mode 100644 index 00000000..75be9742 --- /dev/null +++ b/common/signal/task_test.go @@ -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) +}