mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-07 15:31:23 +08:00
fix: check if synthesizeEvent timeout error and add extra retry
This commit is contained in:
@@ -183,6 +183,8 @@ func (s *DriverSession) RequestWithRetry(method string, urlStr string, rawBody [
|
|||||||
maxRetry = options.MaxRetryTimes
|
maxRetry = options.MaxRetryTimes
|
||||||
}
|
}
|
||||||
|
|
||||||
|
synthesizeEventRetryAdded := false
|
||||||
|
|
||||||
for attempt := 1; attempt <= maxRetry; attempt++ {
|
for attempt := 1; attempt <= maxRetry; attempt++ {
|
||||||
// Execute the request
|
// Execute the request
|
||||||
rawResp, err = s.Request(method, urlStr, rawBody, opts...)
|
rawResp, err = s.Request(method, urlStr, rawBody, opts...)
|
||||||
@@ -193,13 +195,20 @@ func (s *DriverSession) RequestWithRetry(method string, urlStr string, rawBody [
|
|||||||
return rawResp, nil
|
return rawResp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// only for WDA driver, check if "synthesizeEvent timeout" error and add extra retry
|
||||||
|
if strings.Contains(err.Error(), "synthesizeEvent timeout") && !synthesizeEventRetryAdded {
|
||||||
|
log.Warn().Err(err).Msg("synthesizeEvent timeout detected, adding one extra retry")
|
||||||
|
maxRetry++
|
||||||
|
synthesizeEventRetryAdded = true
|
||||||
|
}
|
||||||
|
|
||||||
// Notice: use DeviceHTTPDriverError when request driver failed
|
// Notice: use DeviceHTTPDriverError when request driver failed
|
||||||
lastError = errors.Wrap(code.DeviceHTTPDriverError, err.Error())
|
lastError = errors.Wrap(code.DeviceHTTPDriverError, err.Error())
|
||||||
log.Warn().Err(err).Msgf("request failed, attempt %d/%d", attempt, s.maxRetry)
|
log.Warn().Err(err).Msgf("request failed, attempt %d/%d", attempt, maxRetry)
|
||||||
|
|
||||||
// If this was the last attempt, break
|
// If this was the last attempt, break
|
||||||
if attempt == s.maxRetry {
|
if attempt == maxRetry {
|
||||||
log.Error().Err(lastError).Msgf("all %d retry attempts failed, giving up", s.maxRetry)
|
log.Error().Err(lastError).Msgf("all %d retry attempts failed, giving up", maxRetry)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user