forked from things-labs/wheel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
base_test.go
60 lines (49 loc) · 1.05 KB
/
base_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
package wheel
import (
"fmt"
"testing"
"time"
)
type testJob struct{}
func (sf testJob) Run() {
fmt.Println("job")
}
func TestDefaultBase(t *testing.T) {
wl := New(WithGranularity(DefaultGranularity)).Run()
defer wl.Close()
if got := wl.Len(); got != 0 {
t.Errorf("Len() = %v, want %v", got, 0)
}
if got := wl.HasRunning(); got != true {
t.Errorf("HasRunning() = %v, want %v", got, true)
}
e := NewJobFunc(func() {})
wl.Add(e, time.Millisecond*100)
wl.Delete(e)
wl.Modify(e, time.Millisecond*200)
time.Sleep(time.Second)
e1 := NewTimer().WithGoroutine()
wl.Add(e1, time.Millisecond*150)
e2 := NewTimer().WithGoroutine()
wl.Add(e2, 0)
time.Sleep(time.Second)
// improve couver
wl.Modify(nil, time.Second)
wl.Delete(nil)
wl.Add(nil, time.Second)
}
func ExampleBase_Run() {
wl := New().Run()
wl.AddJobFunc(func() {
fmt.Println("1")
}, time.Millisecond*100)
wl.AddJobFunc(func() {
fmt.Println("2")
}, time.Millisecond*200)
wl.AddJob(&testJob{}, time.Millisecond*300)
time.Sleep(time.Second * 2)
// Output:
// 1
// 2
// job
}