-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpcurl_test.go
57 lines (52 loc) · 1000 Bytes
/
pcurl_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
package main
import (
"io"
"io/ioutil"
"net/http"
"testing"
"time"
)
func Test_Getres(t *testing.T) {
//vars
lock := make(chan bool, 0)
MaxIdleConnections := 20
RequestTimeout := 5
Clientvar = &http.Client{
Transport: &http.Transport{
MaxIdleConnsPerHost: MaxIdleConnections,
DisableCompression: true, // client will compress it by default
},
Timeout: time.Duration(RequestTimeout) * time.Second,
}
call := func(i int) {
res := getres(Clientvar, "http://mirrors.163.com/centos/7/isos/x86_64/", -1, -1)
_, err := io.Copy(ioutil.Discard, res.Body)
if err != nil {
t.Error(err)
} else {
t.Log("#", i, " done @", time.Now().Format("15:04:05.99"))
}
res.Body.Close()
}
// 1st batch
for i := 0; i < 2; i++ {
go func(i int) {
call(i)
lock <- true
}(i)
}
for i := 0; i < 2; i++ {
<-lock
}
time.Sleep(1e9)
// 2nd batch
for i := 2; i < 4; i++ {
go func(i int) {
call(i)
lock <- true
}(i)
}
for i := 0; i < 2; i++ {
<-lock
}
}