forked from things-labs/wheel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wheel_test.go
51 lines (45 loc) · 963 Bytes
/
wheel_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
package wheel
import (
"fmt"
"testing"
"time"
)
func TestWheel(t *testing.T) {
if got := HasRunning(); got {
t.Errorf("HasRunning() = %v, want %v", got, false)
}
if got := Len(); got != 0 {
t.Errorf("Len() = %v, want %v", got, 0)
}
e := NewJobFunc(func() {})
Add(e, time.Millisecond*100)
Delete(e)
Modify(e, time.Millisecond*200)
time.Sleep(time.Second)
if got := HasRunning(); !got {
t.Errorf("HasRunning() = %v, want %v", got, true)
}
e1 := NewTimer().WithGoroutine()
Add(e1, time.Millisecond*150)
e2 := NewTimer().WithGoroutine()
Add(e2, time.Millisecond*100)
time.Sleep(time.Second)
// improve couver
Modify(nil, time.Second)
Delete(nil)
Add(nil, time.Second)
}
func ExampleBase_Len() {
AddJobFunc(func() {
fmt.Println("1")
}, time.Millisecond*100)
AddJobFunc(func() {
fmt.Println("2")
}, time.Millisecond*200)
AddJob(&testJob{}, time.Millisecond*300)
time.Sleep(time.Second * 2)
// Output:
// 1
// 2
// job
}