This repository has been archived on 2020-09-27. You can view files and clone it, but cannot push or open issues or pull requests.
2017-06-21 15:25:18 +02:00
|
|
|
// Package with a lib for cronjobs to run in the background
|
2017-04-05 20:23:29 +02:00
|
|
|
package worker
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2017-05-03 07:16:45 +02:00
|
|
|
// Function to test the Worker
|
2017-04-05 20:23:29 +02:00
|
|
|
func TestWorker(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
runtime := 0
|
|
|
|
|
2017-06-22 20:36:11 +02:00
|
|
|
w := NewWorker(time.Duration(5)*time.Millisecond, func() {
|
2017-04-05 20:23:29 +02:00
|
|
|
runtime = runtime + 1
|
|
|
|
})
|
|
|
|
go w.Start()
|
|
|
|
time.Sleep(time.Duration(18) * time.Millisecond)
|
|
|
|
w.Close()
|
|
|
|
|
|
|
|
assert.Equal(3, runtime)
|
|
|
|
time.Sleep(time.Duration(8) * time.Millisecond)
|
|
|
|
}
|