Skip to content

Commit

Permalink
Merge pull request tsliwowicz#22 from dtuck9/treat-all-2xx-as-successful
Browse files Browse the repository at this point in the history
Treat all 2XX as successful
  • Loading branch information
tsliwowicz committed Jun 22, 2023
2 parents 4be5979 + dba582a commit ae30aa2
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions loader/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const (
)

type LoadCfg struct {
duration int //seconds
duration int // seconds
goroutines int
testUrl string
reqBody string
Expand All @@ -32,7 +32,7 @@ type LoadCfg struct {
allowRedirects bool
disableCompression bool
disableKeepAlive bool
skipVerify bool
skipVerify bool
interrupted int32
clientCert string
clientKey string
Expand All @@ -50,7 +50,7 @@ type RequesterStats struct {
NumErrs int
}

func NewLoadCfg(duration int, //seconds
func NewLoadCfg(duration int, // seconds
goroutines int,
testUrl string,
reqBody string,
Expand Down Expand Up @@ -101,8 +101,8 @@ func escapeUrlStr(in string) string {
}
}

//DoRequest single request implementation. Returns the size of the response and its duration
//On error - returns -1 on both
// DoRequest single request implementation. Returns the size of the response and its duration
// On error - returns -1 on both
func DoRequest(httpClient *http.Client, header map[string]string, method, host, loadUrl, reqBody string) (respSize int, duration time.Duration) {
respSize = -1
duration = -1
Expand Down Expand Up @@ -132,8 +132,8 @@ func DoRequest(httpClient *http.Client, header map[string]string, method, host,
resp, err := httpClient.Do(req)
if err != nil {
fmt.Println("redirect?")
//this is a bit weird. When redirection is prevented, a url.Error is retuned. This creates an issue to distinguish
//between an invalid URL that was provided and and redirection error.
// this is a bit weird. When redirection is prevented, a url.Error is retuned. This creates an issue to distinguish
// between an invalid URL that was provided and and redirection error.
rr, ok := err.(*url.Error)
if !ok {
fmt.Println("An error occured doing request", err, rr)
Expand All @@ -154,7 +154,7 @@ func DoRequest(httpClient *http.Client, header map[string]string, method, host,
if err != nil {
fmt.Println("An error occured reading body", err)
}
if resp.StatusCode == http.StatusOK || resp.StatusCode == http.StatusCreated {
if resp.StatusCode/100 == 2 { // Treat all 2XX as successful
duration = time.Since(start)
respSize = len(body) + int(util.EstimateHttpHeadersSize(resp.Header))
} else if resp.StatusCode == http.StatusMovedPermanently || resp.StatusCode == http.StatusTemporaryRedirect {
Expand All @@ -167,13 +167,13 @@ func DoRequest(httpClient *http.Client, header map[string]string, method, host,
return
}

//Requester a go function for repeatedly making requests and aggregating statistics as long as required
//When it is done, it sends the results using the statsAggregator channel
// Requester a go function for repeatedly making requests and aggregating statistics as long as required
// When it is done, it sends the results using the statsAggregator channel
func (cfg *LoadCfg) RunSingleLoadSession() {
stats := &RequesterStats{MinRequestTime: time.Minute}
start := time.Now()

httpClient, err := client(cfg.disableCompression, cfg.disableKeepAlive, cfg.skipVerify,
httpClient, err := client(cfg.disableCompression, cfg.disableKeepAlive, cfg.skipVerify,
cfg.timeoutms, cfg.allowRedirects, cfg.clientCert, cfg.clientKey, cfg.caCert, cfg.http2)
if err != nil {
log.Fatal(err)
Expand Down

0 comments on commit ae30aa2

Please sign in to comment.