-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain_test.go
49 lines (44 loc) · 851 Bytes
/
main_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
package main
import (
"fmt"
"io/ioutil"
"net/http"
"strconv"
"sync"
"testing"
)
func TestHttp(t *testing.T) {
resp, err := http.Get("http://127.0.0.1:10001/login?storeId=10000")
if err != nil {
fmt.Println(err)
}
defer resp.Body.Close()
data, err := ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Println(err)
}
fmt.Println(string(data))
}
func TestConcurrency(t *testing.T) {
var wg sync.WaitGroup
for i := 0; i < 100000; i++ {
s := strconv.Itoa(i)
wg.Add(1)
go func(storeId string) {
defer wg.Add(-1)
resp, err := http.Get("http://127.0.0.1:10001/login?storeId=" + storeId)
if err != nil {
// fmt.Println(err)
return
}
defer resp.Body.Close()
data, err := ioutil.ReadAll(resp.Body)
if err != nil {
// fmt.Println(err)
return
}
fmt.Println(string(data))
}(s)
}
wg.Wait()
}