forked from da440dil/go-workgroup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server_test.go
77 lines (65 loc) · 1013 Bytes
/
server_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
76
77
package workgroup
import (
"errors"
"testing"
)
func TestServerStopped(t *testing.T) {
var g Group
stop := make(chan error)
g.Add(Server(
func() error {
<-stop
return nil
},
func() error {
close(stop)
return nil
},
))
wait := make(chan struct{})
err := errors.New("err")
g.Add(func(<-chan struct{}) error {
<-wait
return err
})
close(wait)
assert(t, err, g.Run())
}
func TestServerServe(t *testing.T) {
var g Group
wait := make(chan struct{})
err := errors.New("err")
g.Add(Server(
func() error {
<-wait
return err
},
func() error {
return nil
},
))
close(wait)
assert(t, err, g.Run())
}
func TestServerShutdown(t *testing.T) {
var g Group
stop := make(chan error)
err := errors.New("err")
g.Add(Server(
func() error {
<-stop
return nil
},
func() error {
close(stop)
return err
},
))
wait := make(chan struct{})
g.Add(func(<-chan struct{}) error {
<-wait
return nil
})
close(wait)
assert(t, err, g.Run())
}