-
Notifications
You must be signed in to change notification settings - Fork 26
/
web_requester.go
37 lines (29 loc) · 935 Bytes
/
web_requester.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
package requester
import (
"net/http"
"github.com/tylertreat/bench"
)
// WebRequesterFactory implements RequesterFactory by creating a Requester
// which makes GET requests to the provided URL.
type WebRequesterFactory struct {
URL string
}
// GetRequester returns a new Requester, called for each Benchmark connection.
func (w *WebRequesterFactory) GetRequester(uint64) bench.Requester {
return &webRequester{w.URL}
}
// webRequester implements Requester by making a GET request to the provided
// URL.
type webRequester struct {
url string
}
// Setup prepares the Requester for benchmarking.
func (w *webRequester) Setup() error { return nil }
// Request performs a synchronous request to the system under test.
func (w *webRequester) Request() error {
resp, err := http.Get(w.url)
resp.Body.Close()
return err
}
// Teardown is called upon benchmark completion.
func (w *webRequester) Teardown() error { return nil }