-
Notifications
You must be signed in to change notification settings - Fork 127
/
Copy pathjob.go
48 lines (40 loc) · 909 Bytes
/
job.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
package main
import (
"fmt"
"io/ioutil"
"net/http"
"os"
"sync"
"time"
)
func main() {
count := 10
fmt.Printf("Sending %d requests...\n", count)
wg := sync.WaitGroup{}
// URL to the App
url := "http://j2a-app." + os.Getenv("CE_SUBDOMAIN") + ".svc.cluster.local"
// Do all requests to the App in parallel - why not?
for i := 0; i < count; i++ {
wg.Add(1)
go func(i int) {
defer wg.Done()
for j := 0; j < 10; j++ {
res, err := http.Post(url, "", nil)
if err == nil && res.StatusCode/100 == 2 {
break
}
// Something went wrong, pause and try again
body := []byte{}
if res != nil {
body, _ = ioutil.ReadAll(res.Body)
}
fmt.Fprintf(os.Stderr, "%d: err: %s\nhttp res: %#v\nbody:%s",
i, err, res, string(body))
time.Sleep(time.Second)
}
}(i)
}
// Wait for all threads to finish before we exit
wg.Wait()
fmt.Printf("Done\n")
}