golang-lib/worker/main_test.go

29 lines
512 B
Go
Raw Normal View History

2017-05-17 14:56:19 +02:00
// Package with a lib for cronjobs to run in background
package worker
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
// Function to test the Worker
func TestWorker(t *testing.T) {
assert := assert.New(t)
runtime := 0
w := NewWorker(time.Duration(5)*time.Millisecond, func() {
2018-03-22 22:10:05 +01:00
runtime++
2017-05-17 14:56:19 +02:00
})
2018-03-22 22:10:05 +01:00
w.Start()
2017-05-17 14:56:19 +02:00
time.Sleep(time.Duration(18) * time.Millisecond)
w.Close()
2017-10-27 19:40:42 +02:00
time.Sleep(time.Duration(18) * time.Millisecond)
2017-05-17 14:56:19 +02:00
assert.Equal(3, runtime)
2017-10-27 19:40:42 +02:00
assert.Panics(func() {
w.Close()
})
2017-05-17 14:56:19 +02:00
}