-
Notifications
You must be signed in to change notification settings - Fork 32
/
client.go
61 lines (55 loc) · 1.44 KB
/
client.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
package main
import (
"bytes"
"flag"
"math"
"net/http"
"time"
)
var oscillationPeriod = flag.Duration("oscillation-period", time.Hour, "The duration of the rate oscillation period.")
func startClient(servAddr string) {
oscillationFactor := func() float64 {
return 2 + math.Sin(math.Sin(2*math.Pi*float64(time.Since(start))/float64(*oscillationPeriod)))
}
ignoreRequest := func(resp *http.Response, err error) {
if err != nil {
return
}
resp.Body.Close()
}
// GET /api/foo.
go func() {
for {
ignoreRequest(http.Get("http://" + servAddr + "/api/foo"))
time.Sleep(time.Duration(10*oscillationFactor()) * time.Millisecond)
}
}()
// POST /api/foo.
go func() {
for {
ignoreRequest(http.Post("http://"+servAddr+"/api/foo", "text/plain", &bytes.Buffer{}))
time.Sleep(time.Duration(150*oscillationFactor()) * time.Millisecond)
}
}()
// GET /api/bar.
go func() {
for {
ignoreRequest(http.Get("http://" + servAddr + "/api/bar"))
time.Sleep(time.Duration(20*oscillationFactor()) * time.Millisecond)
}
}()
// POST /api/bar.
go func() {
for {
ignoreRequest(http.Post("http://"+servAddr+"/api/bar", "text/plain", &bytes.Buffer{}))
time.Sleep(time.Duration(100*oscillationFactor()) * time.Millisecond)
}
}()
// GET /api/nonexistent.
go func() {
for {
ignoreRequest(http.Get("http://" + servAddr + "/api/nonexistent"))
time.Sleep(time.Duration(500*oscillationFactor()) * time.Millisecond)
}
}()
}