-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgraceful_test.go
46 lines (41 loc) · 889 Bytes
/
graceful_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
package graceful
import (
"testing"
"time"
)
func Test_GoRoutines(t *testing.T) {
Go(func() {
t.Log("routine #1: waiting 2s")
<-time.After(time.Second * 2)
t.Log("routine #1: done")
Go(func() {
t.Log("routine #2: waiting 1s")
<-time.After(time.Second * 1)
t.Log("routine #2: done")
Go(func() {
t.Log("routine #3: waiting 2s")
<-time.After(time.Second * 2)
t.Log("routine #3: resuming, will wait again for 3s")
<-time.After(time.Second * 3)
t.Log("routine #3: done")
})
})
Go(func() {
t.Log("routine #4: waiting 1s")
<-time.After(time.Second * 1)
t.Log("routine #4: done")
})
})
Go(func() {
t.Log("routine #5: waiting 2s")
<-time.After(time.Second * 2)
t.Log("routine #5: done")
})
Go(func() {
t.Log("routine #6: waiting 3s")
<-time.After(time.Second * 3)
t.Log("routine #6: done")
})
close(sig)
Wait()
}