github.com/netdata/go.d.plugin@v0.58.1/modules/vsphere/task_test.go (about) 1 // SPDX-License-Identifier: GPL-3.0-or-later 2 3 package vsphere 4 5 import ( 6 "sync/atomic" 7 "testing" 8 "time" 9 10 "github.com/stretchr/testify/assert" 11 ) 12 13 func Test_task(t *testing.T) { 14 var i int64 15 job := func() { 16 atomic.AddInt64(&i, 1) 17 } 18 19 task := newTask(job, time.Millisecond*200) 20 defer task.stop() 21 time.Sleep(time.Second) 22 assert.True(t, atomic.LoadInt64(&i) > 0) 23 } 24 25 func Test_task_isStopped(t *testing.T) { 26 task := newTask(func() {}, time.Second) 27 assert.False(t, task.isStopped()) 28 29 task.stop() 30 time.Sleep(time.Millisecond * 500) 31 assert.True(t, task.isStopped()) 32 } 33 34 func Test_task_isRunning(t *testing.T) { 35 task := newTask(func() {}, time.Second) 36 assert.True(t, task.isRunning()) 37 38 task.stop() 39 time.Sleep(time.Millisecond * 500) 40 assert.False(t, task.isRunning()) 41 }