-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcron_test.go
61 lines (49 loc) · 1.26 KB
/
cron_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package gouse
import (
"testing"
"time"
)
func TestNewCronJob(t *testing.T) {
duration := time.Second * 1
stopAfter := time.Second * 5
callback := func() {}
cronJob := NewCronJob(duration, stopAfter, callback)
if cronJob.duration != duration {
t.Errorf("Expected duration %v, but got %v", duration, cronJob.duration)
}
if cronJob.stopAfter != stopAfter {
t.Errorf("Expected stopAfter %v, but got %v", stopAfter, cronJob.stopAfter)
}
if cronJob.callback == nil {
t.Error("Expected callback to be set, but it was nil")
}
if cronJob.stopChan == nil {
t.Error("Expected stopChan to be set, but it was nil")
}
}
func TestCronJobStartAndWait(t *testing.T) {
duration := time.Millisecond * 10
stopAfter := time.Millisecond * 50
callbackCalled := false
callback := func() {
callbackCalled = true
}
cronJob := NewCronJob(duration, stopAfter, callback)
cronJob.StartJob()
cronJob.WaitJob()
if !callbackCalled {
t.Error("Expected callback to be called, but it wasn't")
}
}
func TestRunJob(t *testing.T) {
duration := uint64(1)
stopAfter := uint64(2)
callbackCalled := false
callback := func() {
callbackCalled = true
}
RunJob(duration, stopAfter, callback)
if !callbackCalled {
t.Error("Expected callback to be called, but it wasn't")
}
}