-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgo_pool_test.go
58 lines (51 loc) · 986 Bytes
/
go_pool_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
package gopool
import "testing"
import "time"
func TestInstantiate(t *testing.T) {
var gp GoPool //Explicit type here to make New returns a GoPool
var err error
gp, err = New(100)
if err != nil {
t.Error(err)
}
if gp == nil {
t.Error("gp was nil")
}
}
func TestInstantiateMax0(t *testing.T) {
_, err := New(0)
if err == nil {
t.Error("New accepted 0 pool size")
}
}
func TestGoPoolBasic(t *testing.T) {
gp, err := New(1)
if err != nil {
t.Fatal(err)
}
ch := make(chan bool)
timer := time.After(100 * time.Millisecond)
gp.Go(func() { ch <- true })
select {
case _ = <-ch:
case _ = <-timer:
t.Error("Timed out")
}
}
func TestGoPoolConc(t *testing.T) {
gp, err := New(1)
if err != nil {
t.Fatal(err)
}
ch := make(chan bool)
//The lines below will timeout if gp.Go doesn't run concurrently
gp.Go(func() {
timer := time.After(100 * time.Millisecond)
select {
case _ = <-ch:
case _ = <-timer:
t.Error("Timed out")
}
})
ch <- true
}