зеркало из https://github.com/microsoft/LaBench.git
Address PR comment, use maybePanic
This commit is contained in:
Родитель
d727ae4442
Коммит
86dc0d90df
|
@ -25,7 +25,7 @@ const (
|
||||||
type RequesterFactory interface {
|
type RequesterFactory interface {
|
||||||
// GetRequester returns a new Requester, called for each Benchmark
|
// GetRequester returns a new Requester, called for each Benchmark
|
||||||
// connection.
|
// connection.
|
||||||
GetRequester(number uint64) (Requester, error)
|
GetRequester(number uint64) Requester
|
||||||
}
|
}
|
||||||
|
|
||||||
// Requester synchronously issues requests for a particular system under test.
|
// 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++ {
|
for i := uint64(0); i < b.connections; i++ {
|
||||||
i := i
|
i := i
|
||||||
go func() {
|
go func() {
|
||||||
requester, _ := b.factory.GetRequester(i)
|
b.worker(b.factory.GetRequester(i), ticker, results, errors)
|
||||||
b.worker(requester, ticker, results, errors)
|
|
||||||
// log.Printf("Worker %d done\n", i)
|
// log.Printf("Worker %d done\n", i)
|
||||||
wg.Done()
|
wg.Done()
|
||||||
}()
|
}()
|
||||||
|
|
2
main.go
2
main.go
|
@ -69,7 +69,7 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if conf.Request.HTTPMethod == "" {
|
if conf.Request.HTTPMethod == "" {
|
||||||
if conf.Request.Body == "" && conf.Request.BodyPath == "" {
|
if conf.Request.Body == "" && conf.Request.BodyFile == "" {
|
||||||
conf.Request.HTTPMethod = http.MethodGet
|
conf.Request.HTTPMethod = http.MethodGet
|
||||||
} else {
|
} else {
|
||||||
conf.Request.HTTPMethod = http.MethodPost
|
conf.Request.HTTPMethod = http.MethodPost
|
||||||
|
|
|
@ -92,7 +92,7 @@ type WebRequesterFactory struct {
|
||||||
Hosts []string `yaml:"Hosts"`
|
Hosts []string `yaml:"Hosts"`
|
||||||
Headers map[string]string `yaml:"Headers"`
|
Headers map[string]string `yaml:"Headers"`
|
||||||
Body string `yaml:"Body"`
|
Body string `yaml:"Body"`
|
||||||
BodyPath string `yaml:"BodyPath"`
|
BodyFile string `yaml:"BodyFile"`
|
||||||
ExpectedHTTPStatusCode int `yaml:"ExpectedHTTPStatusCode"`
|
ExpectedHTTPStatusCode int `yaml:"ExpectedHTTPStatusCode"`
|
||||||
HTTPMethod string `yaml:"HTTPMethod"`
|
HTTPMethod string `yaml:"HTTPMethod"`
|
||||||
|
|
||||||
|
@ -100,7 +100,7 @@ type WebRequesterFactory struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetRequester returns a new Requester, called for each Benchmark connection.
|
// 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 len(w.expandedHeaders) != len(w.Headers) {
|
||||||
if w.expandedHeaders == nil {
|
if w.expandedHeaders == nil {
|
||||||
expandedHeaders := make(map[string][]string)
|
expandedHeaders := make(map[string][]string)
|
||||||
|
@ -110,16 +110,16 @@ func (w *WebRequesterFactory) GetRequester(uint64) (bench.Requester, error) {
|
||||||
w.expandedHeaders = expandedHeaders
|
w.expandedHeaders = expandedHeaders
|
||||||
}
|
}
|
||||||
|
|
||||||
// if BodyPath is specified Body is ignored
|
// if BodyFile is specified Body is ignored
|
||||||
if w.BodyPath != "" {
|
if w.BodyFile != "" {
|
||||||
content, err := ioutil.ReadFile(w.BodyPath)
|
content, err := ioutil.ReadFile(w.BodyFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
maybePanic(err)
|
||||||
}
|
}
|
||||||
w.Body = string(content)
|
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
|
// webRequester implements Requester by making a GET request to the provided
|
||||||
|
|
Загрузка…
Ссылка в новой задаче