mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-11 18:11:21 +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
|
||||
}
|
||||
|
||||
synthesizeEventRetryAdded := false
|
||||
|
||||
for attempt := 1; attempt <= maxRetry; attempt++ {
|
||||
// Execute the request
|
||||
rawResp, err = s.Request(method, urlStr, rawBody, opts...)
|
||||
@@ -193,13 +195,20 @@ func (s *DriverSession) RequestWithRetry(method string, urlStr string, rawBody [
|
||||
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
|
||||
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 attempt == s.maxRetry {
|
||||
log.Error().Err(lastError).Msgf("all %d retry attempts failed, giving up", s.maxRetry)
|
||||
if attempt == maxRetry {
|
||||
log.Error().Err(lastError).Msgf("all %d retry attempts failed, giving up", maxRetry)
|
||||
break
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user