-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathqueue_test.go
75 lines (70 loc) · 1.15 KB
/
queue_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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package queue
import (
"testing"
)
func TestAdd(t *testing.T) {
q := New(10)
defer q.Close()
n := 5
for i := 0; i != n; i++ {
q.Add()
go func(c int) {
}(i)
}
if jobs := q.Current(); jobs != n {
t.Errorf("Expected %d got %d", n, jobs)
t.Fail()
}
}
func TestWait(t *testing.T) {
q := New(10)
defer q.Close()
n := 5
for i := 0; i != n; i++ {
q.Add()
go func(c int) {
defer q.Done()
}(i)
}
// wait for the end of the all jobs
q.Wait()
if jobs := q.Current(); jobs != 0 {
t.Errorf("Expected %d got %d", 0, jobs)
t.Fail()
}
}
func TestDone(t *testing.T) {
q := New(10)
defer q.Close()
n := 5
for i := 0; i != n; i++ {
q.Add()
go func(c int) {
// let all the jobs done
defer q.Done()
}(i)
}
// wait for the end of the all jobs
q.Wait()
if jobs := q.Current(); jobs != 0 {
t.Errorf("Expected %d got %d", 0, jobs)
t.Fail()
}
}
func TestCurrent(t *testing.T) {
q := New(10)
defer q.Close()
n := 5
for i := 0; i != n; i++ {
q.Add()
go func(c int) {
defer q.Done()
}(i)
}
q.Wait()
// current should be 0
if jobs := q.Current(); jobs != 0 {
t.Errorf("Expected %d got %d", 0, jobs)
t.Fail()
}
}