Address PR comment, use maybePanic

This commit is contained in:
Joon Lee 2019-11-03 21:05:57 -08:00
Родитель d727ae4442
Коммит 86dc0d90df
3 изменённых файлов: 10 добавлений и 11 удалений

Просмотреть файл

@ -25,7 +25,7 @@ const (
type RequesterFactory interface {
// GetRequester returns a new Requester, called for each Benchmark
// connection.
GetRequester(number uint64) (Requester, error)
GetRequester(number uint64) Requester
}
// Requester synchronously issues requests for a particular system under test.
@ -107,8 +107,7 @@ func (b *Benchmark) Run(outputJson bool, forceTightTicker bool) (*Summary, error
for i := uint64(0); i < b.connections; i++ {
i := i
go func() {
requester, _ := b.factory.GetRequester(i)
b.worker(requester, ticker, results, errors)
b.worker(b.factory.GetRequester(i), ticker, results, errors)
// log.Printf("Worker %d done\n", i)
wg.Done()
}()

Просмотреть файл

@ -69,7 +69,7 @@ func main() {
}
if conf.Request.HTTPMethod == "" {
if conf.Request.Body == "" && conf.Request.BodyPath == "" {
if conf.Request.Body == "" && conf.Request.BodyFile == "" {
conf.Request.HTTPMethod = http.MethodGet
} else {
conf.Request.HTTPMethod = http.MethodPost

Просмотреть файл

@ -92,7 +92,7 @@ type WebRequesterFactory struct {
Hosts []string `yaml:"Hosts"`
Headers map[string]string `yaml:"Headers"`
Body string `yaml:"Body"`
BodyPath string `yaml:"BodyPath"`
BodyFile string `yaml:"BodyFile"`
ExpectedHTTPStatusCode int `yaml:"ExpectedHTTPStatusCode"`
HTTPMethod string `yaml:"HTTPMethod"`
@ -100,7 +100,7 @@ type WebRequesterFactory struct {
}
// GetRequester returns a new Requester, called for each Benchmark connection.
func (w *WebRequesterFactory) GetRequester(uint64) (bench.Requester, error) {
func (w *WebRequesterFactory) GetRequester(uint64) bench.Requester {
// if len(w.expandedHeaders) != len(w.Headers) {
if w.expandedHeaders == nil {
expandedHeaders := make(map[string][]string)
@ -110,16 +110,16 @@ func (w *WebRequesterFactory) GetRequester(uint64) (bench.Requester, error) {
w.expandedHeaders = expandedHeaders
}
// if BodyPath is specified Body is ignored
if w.BodyPath != "" {
content, err := ioutil.ReadFile(w.BodyPath)
// if BodyFile is specified Body is ignored
if w.BodyFile != "" {
content, err := ioutil.ReadFile(w.BodyFile)
if err != nil {
return nil, err
maybePanic(err)
}
w.Body = string(content)
}
return &webRequester{w.URL, w.URLs, w.Hosts, w.expandedHeaders, w.Body, w.ExpectedHTTPStatusCode, w.HTTPMethod}, nil
return &webRequester{w.URL, w.URLs, w.Hosts, w.expandedHeaders, w.Body, w.ExpectedHTTPStatusCode, w.HTTPMethod}
}
// webRequester implements Requester by making a GET request to the provided