зеркало из https://github.com/microsoft/LaBench.git
Add support to fetch request body from file
This commit is contained in:
Родитель
57e127f1f1
Коммит
f60fa1bad4
|
@ -25,7 +25,7 @@ const (
|
|||
type RequesterFactory interface {
|
||||
// GetRequester returns a new Requester, called for each Benchmark
|
||||
// connection.
|
||||
GetRequester(number uint64) Requester
|
||||
GetRequester(number uint64) (Requester, error)
|
||||
}
|
||||
|
||||
// Requester synchronously issues requests for a particular system under test.
|
||||
|
@ -107,7 +107,8 @@ func (b *Benchmark) Run(outputJson bool, forceTightTicker bool) (*Summary, error
|
|||
for i := uint64(0); i < b.connections; i++ {
|
||||
i := i
|
||||
go func() {
|
||||
b.worker(b.factory.GetRequester(i), ticker, results, errors)
|
||||
requester, _ := b.factory.GetRequester(i)
|
||||
b.worker(requester, ticker, results, errors)
|
||||
// log.Printf("Worker %d done\n", i)
|
||||
wg.Done()
|
||||
}()
|
||||
|
|
|
@ -92,6 +92,7 @@ type WebRequesterFactory struct {
|
|||
Hosts []string `yaml:"Hosts"`
|
||||
Headers map[string]string `yaml:"Headers"`
|
||||
Body string `yaml:"Body"`
|
||||
BodyPath string `yaml:"BodyPath"`
|
||||
ExpectedHTTPStatusCode int `yaml:"ExpectedHTTPStatusCode"`
|
||||
HTTPMethod string `yaml:"HTTPMethod"`
|
||||
|
||||
|
@ -99,7 +100,7 @@ type WebRequesterFactory struct {
|
|||
}
|
||||
|
||||
// GetRequester returns a new Requester, called for each Benchmark connection.
|
||||
func (w *WebRequesterFactory) GetRequester(uint64) bench.Requester {
|
||||
func (w *WebRequesterFactory) GetRequester(uint64) (bench.Requester, error) {
|
||||
// if len(w.expandedHeaders) != len(w.Headers) {
|
||||
if w.expandedHeaders == nil {
|
||||
expandedHeaders := make(map[string][]string)
|
||||
|
@ -109,7 +110,16 @@ func (w *WebRequesterFactory) GetRequester(uint64) bench.Requester {
|
|||
w.expandedHeaders = expandedHeaders
|
||||
}
|
||||
|
||||
return &webRequester{w.URL, w.URLs, w.Hosts, w.expandedHeaders, w.Body, w.ExpectedHTTPStatusCode, w.HTTPMethod}
|
||||
// if BodyPath is specified Body is ignored
|
||||
if w.BodyPath != "" {
|
||||
content, err := ioutil.ReadFile(w.BodyPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
w.Body = string(content)
|
||||
}
|
||||
|
||||
return &webRequester{w.URL, w.URLs, w.Hosts, w.expandedHeaders, w.Body, w.ExpectedHTTPStatusCode, w.HTTPMethod}, nil
|
||||
}
|
||||
|
||||
// webRequester implements Requester by making a GET request to the provided
|
||||
|
|
Загрузка…
Ссылка в новой задаче