Skip to content

Commit 172c921

Browse files
authored
Merge pull request #36 from slok/slok/moar-requests
Add more requests in integration tests
2 parents d6d4bd6 + 4950408 commit 172c921

File tree

2 files changed

+72
-69
lines changed

2 files changed

+72
-69
lines changed

test/integration/data_test.go

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -6,42 +6,42 @@ import "time"
66

77
var (
88
expReqs = []handlerConfig{
9-
{Path: "/test/1", Method: "GET", Code: 201, ReturnData: "1", sleepDuration: 45 * time.Millisecond},
10-
{Path: "/test/2", Method: "POST", Code: 202, ReturnData: "22", sleepDuration: 95 * time.Millisecond},
11-
{Path: "/test/3", Method: "PATCH", Code: 203, ReturnData: "333", sleepDuration: 145 * time.Millisecond},
12-
{Path: "/test/4", Method: "DELETE", Code: 205, ReturnData: "4444", sleepDuration: 195 * time.Millisecond},
9+
{Path: "/test/1", Method: "GET", Code: 201, ReturnData: "1", SleepDuration: 45 * time.Millisecond, NumberRequests: 10},
10+
{Path: "/test/2", Method: "POST", Code: 202, ReturnData: "22", SleepDuration: 95 * time.Millisecond, NumberRequests: 9},
11+
{Path: "/test/3", Method: "PATCH", Code: 203, ReturnData: "333", SleepDuration: 145 * time.Millisecond, NumberRequests: 8},
12+
{Path: "/test/4", Method: "DELETE", Code: 205, ReturnData: "4444", SleepDuration: 195 * time.Millisecond, NumberRequests: 7},
1313
}
1414

1515
expMetrics = []string{
1616
`# HELP http_request_duration_seconds The latency of the HTTP requests.`,
1717
`# TYPE http_request_duration_seconds histogram`,
18-
`http_request_duration_seconds_bucket{code="201",handler="/test/1",method="GET",service="integration",le="0.05"} 1`,
19-
`http_request_duration_seconds_bucket{code="201",handler="/test/1",method="GET",service="integration",le="0.1"} 1`,
20-
`http_request_duration_seconds_bucket{code="201",handler="/test/1",method="GET",service="integration",le="0.15"} 1`,
21-
`http_request_duration_seconds_bucket{code="201",handler="/test/1",method="GET",service="integration",le="0.2"} 1`,
22-
`http_request_duration_seconds_bucket{code="201",handler="/test/1",method="GET",service="integration",le="+Inf"} 1`,
23-
`http_request_duration_seconds_count{code="201",handler="/test/1",method="GET",service="integration"} 1`,
18+
`http_request_duration_seconds_bucket{code="201",handler="/test/1",method="GET",service="integration",le="0.05"} 10`,
19+
`http_request_duration_seconds_bucket{code="201",handler="/test/1",method="GET",service="integration",le="0.1"} 10`,
20+
`http_request_duration_seconds_bucket{code="201",handler="/test/1",method="GET",service="integration",le="0.15"} 10`,
21+
`http_request_duration_seconds_bucket{code="201",handler="/test/1",method="GET",service="integration",le="0.2"} 10`,
22+
`http_request_duration_seconds_bucket{code="201",handler="/test/1",method="GET",service="integration",le="+Inf"} 10`,
23+
`http_request_duration_seconds_count{code="201",handler="/test/1",method="GET",service="integration"} 10`,
2424

2525
`http_request_duration_seconds_bucket{code="202",handler="/test/2",method="POST",service="integration",le="0.05"} 0`,
26-
`http_request_duration_seconds_bucket{code="202",handler="/test/2",method="POST",service="integration",le="0.1"} 1`,
27-
`http_request_duration_seconds_bucket{code="202",handler="/test/2",method="POST",service="integration",le="0.15"} 1`,
28-
`http_request_duration_seconds_bucket{code="202",handler="/test/2",method="POST",service="integration",le="0.2"} 1`,
29-
`http_request_duration_seconds_bucket{code="202",handler="/test/2",method="POST",service="integration",le="+Inf"} 1`,
30-
`http_request_duration_seconds_count{code="202",handler="/test/2",method="POST",service="integration"} 1`,
26+
`http_request_duration_seconds_bucket{code="202",handler="/test/2",method="POST",service="integration",le="0.1"} 9`,
27+
`http_request_duration_seconds_bucket{code="202",handler="/test/2",method="POST",service="integration",le="0.15"} 9`,
28+
`http_request_duration_seconds_bucket{code="202",handler="/test/2",method="POST",service="integration",le="0.2"} 9`,
29+
`http_request_duration_seconds_bucket{code="202",handler="/test/2",method="POST",service="integration",le="+Inf"} 9`,
30+
`http_request_duration_seconds_count{code="202",handler="/test/2",method="POST",service="integration"} 9`,
3131

3232
`http_request_duration_seconds_bucket{code="203",handler="/test/3",method="PATCH",service="integration",le="0.05"} 0`,
3333
`http_request_duration_seconds_bucket{code="203",handler="/test/3",method="PATCH",service="integration",le="0.1"} 0`,
34-
`http_request_duration_seconds_bucket{code="203",handler="/test/3",method="PATCH",service="integration",le="0.15"} 1`,
35-
`http_request_duration_seconds_bucket{code="203",handler="/test/3",method="PATCH",service="integration",le="0.2"} 1`,
36-
`http_request_duration_seconds_bucket{code="203",handler="/test/3",method="PATCH",service="integration",le="+Inf"} 1`,
37-
`http_request_duration_seconds_count{code="203",handler="/test/3",method="PATCH",service="integration"} 1`,
34+
`http_request_duration_seconds_bucket{code="203",handler="/test/3",method="PATCH",service="integration",le="0.15"} 8`,
35+
`http_request_duration_seconds_bucket{code="203",handler="/test/3",method="PATCH",service="integration",le="0.2"} 8`,
36+
`http_request_duration_seconds_bucket{code="203",handler="/test/3",method="PATCH",service="integration",le="+Inf"} 8`,
37+
`http_request_duration_seconds_count{code="203",handler="/test/3",method="PATCH",service="integration"} 8`,
3838

3939
`http_request_duration_seconds_bucket{code="205",handler="/test/4",method="DELETE",service="integration",le="0.05"} 0`,
4040
`http_request_duration_seconds_bucket{code="205",handler="/test/4",method="DELETE",service="integration",le="0.1"} 0`,
4141
`http_request_duration_seconds_bucket{code="205",handler="/test/4",method="DELETE",service="integration",le="0.15"} 0`,
42-
`http_request_duration_seconds_bucket{code="205",handler="/test/4",method="DELETE",service="integration",le="0.2"} 1`,
43-
`http_request_duration_seconds_bucket{code="205",handler="/test/4",method="DELETE",service="integration",le="+Inf"} 1`,
44-
`http_request_duration_seconds_count{code="205",handler="/test/4",method="DELETE",service="integration"} 1`,
42+
`http_request_duration_seconds_bucket{code="205",handler="/test/4",method="DELETE",service="integration",le="0.2"} 7`,
43+
`http_request_duration_seconds_bucket{code="205",handler="/test/4",method="DELETE",service="integration",le="+Inf"} 7`,
44+
`http_request_duration_seconds_count{code="205",handler="/test/4",method="DELETE",service="integration"} 7`,
4545

4646
`# HELP http_requests_inflight The number of inflight requests being handled at the same time.`,
4747
`# TYPE http_requests_inflight gauge`,
@@ -52,40 +52,40 @@ var (
5252

5353
`# HELP http_response_size_bytes The size of the HTTP responses.`,
5454
`# TYPE http_response_size_bytes histogram`,
55-
`http_response_size_bytes_bucket{code="201",handler="/test/1",method="GET",service="integration",le="1"} 1`,
56-
`http_response_size_bytes_bucket{code="201",handler="/test/1",method="GET",service="integration",le="2"} 1`,
57-
`http_response_size_bytes_bucket{code="201",handler="/test/1",method="GET",service="integration",le="3"} 1`,
58-
`http_response_size_bytes_bucket{code="201",handler="/test/1",method="GET",service="integration",le="4"} 1`,
59-
`http_response_size_bytes_bucket{code="201",handler="/test/1",method="GET",service="integration",le="5"} 1`,
60-
`http_response_size_bytes_bucket{code="201",handler="/test/1",method="GET",service="integration",le="+Inf"} 1`,
61-
`http_response_size_bytes_sum{code="201",handler="/test/1",method="GET",service="integration"} 1`,
62-
`http_response_size_bytes_count{code="201",handler="/test/1",method="GET",service="integration"} 1`,
55+
`http_response_size_bytes_bucket{code="201",handler="/test/1",method="GET",service="integration",le="1"} 10`,
56+
`http_response_size_bytes_bucket{code="201",handler="/test/1",method="GET",service="integration",le="2"} 10`,
57+
`http_response_size_bytes_bucket{code="201",handler="/test/1",method="GET",service="integration",le="3"} 10`,
58+
`http_response_size_bytes_bucket{code="201",handler="/test/1",method="GET",service="integration",le="4"} 10`,
59+
`http_response_size_bytes_bucket{code="201",handler="/test/1",method="GET",service="integration",le="5"} 10`,
60+
`http_response_size_bytes_bucket{code="201",handler="/test/1",method="GET",service="integration",le="+Inf"} 10`,
61+
`http_response_size_bytes_sum{code="201",handler="/test/1",method="GET",service="integration"} 10`,
62+
`http_response_size_bytes_count{code="201",handler="/test/1",method="GET",service="integration"} 10`,
6363

6464
`http_response_size_bytes_bucket{code="202",handler="/test/2",method="POST",service="integration",le="1"} 0`,
65-
`http_response_size_bytes_bucket{code="202",handler="/test/2",method="POST",service="integration",le="2"} 1`,
66-
`http_response_size_bytes_bucket{code="202",handler="/test/2",method="POST",service="integration",le="3"} 1`,
67-
`http_response_size_bytes_bucket{code="202",handler="/test/2",method="POST",service="integration",le="4"} 1`,
68-
`http_response_size_bytes_bucket{code="202",handler="/test/2",method="POST",service="integration",le="5"} 1`,
69-
`http_response_size_bytes_bucket{code="202",handler="/test/2",method="POST",service="integration",le="+Inf"} 1`,
70-
`http_response_size_bytes_sum{code="202",handler="/test/2",method="POST",service="integration"} 2`,
71-
`http_response_size_bytes_count{code="202",handler="/test/2",method="POST",service="integration"} 1`,
65+
`http_response_size_bytes_bucket{code="202",handler="/test/2",method="POST",service="integration",le="2"} 9`,
66+
`http_response_size_bytes_bucket{code="202",handler="/test/2",method="POST",service="integration",le="3"} 9`,
67+
`http_response_size_bytes_bucket{code="202",handler="/test/2",method="POST",service="integration",le="4"} 9`,
68+
`http_response_size_bytes_bucket{code="202",handler="/test/2",method="POST",service="integration",le="5"} 9`,
69+
`http_response_size_bytes_bucket{code="202",handler="/test/2",method="POST",service="integration",le="+Inf"} 9`,
70+
`http_response_size_bytes_sum{code="202",handler="/test/2",method="POST",service="integration"} 18`,
71+
`http_response_size_bytes_count{code="202",handler="/test/2",method="POST",service="integration"} 9`,
7272

7373
`http_response_size_bytes_bucket{code="203",handler="/test/3",method="PATCH",service="integration",le="1"} 0`,
7474
`http_response_size_bytes_bucket{code="203",handler="/test/3",method="PATCH",service="integration",le="2"} 0`,
75-
`http_response_size_bytes_bucket{code="203",handler="/test/3",method="PATCH",service="integration",le="3"} 1`,
76-
`http_response_size_bytes_bucket{code="203",handler="/test/3",method="PATCH",service="integration",le="4"} 1`,
77-
`http_response_size_bytes_bucket{code="203",handler="/test/3",method="PATCH",service="integration",le="5"} 1`,
78-
`http_response_size_bytes_bucket{code="203",handler="/test/3",method="PATCH",service="integration",le="+Inf"} 1`,
79-
`http_response_size_bytes_sum{code="203",handler="/test/3",method="PATCH",service="integration"} 3`,
80-
`http_response_size_bytes_count{code="203",handler="/test/3",method="PATCH",service="integration"} 1`,
75+
`http_response_size_bytes_bucket{code="203",handler="/test/3",method="PATCH",service="integration",le="3"} 8`,
76+
`http_response_size_bytes_bucket{code="203",handler="/test/3",method="PATCH",service="integration",le="4"} 8`,
77+
`http_response_size_bytes_bucket{code="203",handler="/test/3",method="PATCH",service="integration",le="5"} 8`,
78+
`http_response_size_bytes_bucket{code="203",handler="/test/3",method="PATCH",service="integration",le="+Inf"} 8`,
79+
`http_response_size_bytes_sum{code="203",handler="/test/3",method="PATCH",service="integration"} 24`,
80+
`http_response_size_bytes_count{code="203",handler="/test/3",method="PATCH",service="integration"} 8`,
8181

8282
`http_response_size_bytes_bucket{code="205",handler="/test/4",method="DELETE",service="integration",le="1"} 0`,
8383
`http_response_size_bytes_bucket{code="205",handler="/test/4",method="DELETE",service="integration",le="2"} 0`,
8484
`http_response_size_bytes_bucket{code="205",handler="/test/4",method="DELETE",service="integration",le="3"} 0`,
85-
`http_response_size_bytes_bucket{code="205",handler="/test/4",method="DELETE",service="integration",le="4"} 1`,
86-
`http_response_size_bytes_bucket{code="205",handler="/test/4",method="DELETE",service="integration",le="5"} 1`,
87-
`http_response_size_bytes_bucket{code="205",handler="/test/4",method="DELETE",service="integration",le="+Inf"} 1`,
88-
`http_response_size_bytes_sum{code="205",handler="/test/4",method="DELETE",service="integration"} 4`,
89-
`http_response_size_bytes_count{code="205",handler="/test/4",method="DELETE",service="integration"} 1`,
85+
`http_response_size_bytes_bucket{code="205",handler="/test/4",method="DELETE",service="integration",le="4"} 7`,
86+
`http_response_size_bytes_bucket{code="205",handler="/test/4",method="DELETE",service="integration",le="5"} 7`,
87+
`http_response_size_bytes_bucket{code="205",handler="/test/4",method="DELETE",service="integration",le="+Inf"} 7`,
88+
`http_response_size_bytes_sum{code="205",handler="/test/4",method="DELETE",service="integration"} 28`,
89+
`http_response_size_bytes_count{code="205",handler="/test/4",method="DELETE",service="integration"} 7`,
9090
}
9191
)

test/integration/integration_test.go

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,12 @@ import (
3232
// handlerConfig is the configuration the servers will need to set up to properly
3333
// execute the tests.
3434
type handlerConfig struct {
35-
Path string
36-
Code int
37-
Method string
38-
ReturnData string
39-
sleepDuration time.Duration
35+
Path string
36+
Code int
37+
Method string
38+
ReturnData string
39+
SleepDuration time.Duration
40+
NumberRequests int
4041
}
4142

4243
func TestMiddlewarePrometheus(t *testing.T) {
@@ -85,16 +86,18 @@ func testMiddlewareRequests(t *testing.T, h http.Handler, expReqs []handlerConfi
8586

8687
// Make all the requests.
8788
for _, config := range expReqs {
88-
r, err := http.NewRequest(config.Method, server.URL+config.Path, nil)
89-
require.NoError(err)
90-
resp, err := http.DefaultClient.Do(r)
91-
require.NoError(err)
92-
93-
// Check.
94-
assert.Equal(config.Code, resp.StatusCode)
95-
b, err := ioutil.ReadAll(resp.Body)
96-
require.NoError(err)
97-
assert.Equal(config.ReturnData, string(b))
89+
for i := 0; i < config.NumberRequests; i++ {
90+
r, err := http.NewRequest(config.Method, server.URL+config.Path, nil)
91+
require.NoError(err)
92+
resp, err := http.DefaultClient.Do(r)
93+
require.NoError(err)
94+
95+
// Check.
96+
assert.Equal(config.Code, resp.StatusCode)
97+
b, err := ioutil.ReadAll(resp.Body)
98+
require.NoError(err)
99+
assert.Equal(config.ReturnData, string(b))
100+
}
98101
}
99102
}
100103

@@ -134,7 +137,7 @@ func prepareHandlerSTD(m middleware.Middleware, hc []handlerConfig) http.Handler
134137
return
135138
}
136139

137-
time.Sleep(h.sleepDuration)
140+
time.Sleep(h.SleepDuration)
138141
w.WriteHeader(h.Code)
139142
// nolint: errcheck
140143
w.Write([]byte(h.ReturnData))
@@ -158,7 +161,7 @@ func prepareHandlerNegroni(m middleware.Middleware, hc []handlerConfig) http.Han
158161
return
159162
}
160163

161-
time.Sleep(h.sleepDuration)
164+
time.Sleep(h.SleepDuration)
162165
w.WriteHeader(h.Code)
163166
// nolint: errcheck
164167
w.Write([]byte(h.ReturnData))
@@ -180,7 +183,7 @@ func prepareHandlerHTTPRouter(m middleware.Middleware, hc []handlerConfig) http.
180183
for _, h := range hc {
181184
h := h
182185
hr := func(w http.ResponseWriter, _ *http.Request, _ httprouter.Params) {
183-
time.Sleep(h.sleepDuration)
186+
time.Sleep(h.SleepDuration)
184187
w.WriteHeader(h.Code)
185188
// nolint: errcheck
186189
w.Write([]byte(h.ReturnData))
@@ -203,7 +206,7 @@ func prepareHandlerGorestful(m middleware.Middleware, hc []handlerConfig) http.H
203206
for _, h := range hc {
204207
h := h
205208
ws.Route(ws.Method(h.Method).Path(h.Path).To(func(_ *gorestful.Request, resp *gorestful.Response) {
206-
time.Sleep(h.sleepDuration)
209+
time.Sleep(h.SleepDuration)
207210
resp.WriteHeader(h.Code)
208211
// nolint: errcheck
209212
resp.Write([]byte(h.ReturnData))
@@ -223,7 +226,7 @@ func prepareHandlerGin(m middleware.Middleware, hc []handlerConfig) http.Handler
223226
for _, h := range hc {
224227
h := h
225228
e.Handle(h.Method, h.Path, func(c *gin.Context) {
226-
time.Sleep(h.sleepDuration)
229+
time.Sleep(h.SleepDuration)
227230
c.String(h.Code, h.ReturnData)
228231
})
229232
}
@@ -240,7 +243,7 @@ func prepareHandlerEcho(m middleware.Middleware, hc []handlerConfig) http.Handle
240243
for _, h := range hc {
241244
h := h
242245
e.Add(h.Method, h.Path, func(c echo.Context) error {
243-
time.Sleep(h.sleepDuration)
246+
time.Sleep(h.SleepDuration)
244247
return c.String(h.Code, h.ReturnData)
245248
})
246249
}

0 commit comments

Comments
 (0)