Skip to content

Commit 94277a5

Browse files
authored
Add http::ErrorCodes to DefaultRetryCondition() (#1213)
Default retry condition func must also consider http::ErrorCodes. Unit test tuned accordingly. Relates-To: OLPEDGE-2567 Signed-off-by: Kostiantyn Zvieriev <[email protected]>
1 parent d21cf38 commit 94277a5

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

olp-cpp-sdk-core/src/client/OlpClientSettings.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ bool DefaultRetryCondition(const HttpResponse& response) {
3333
response.status == http::HttpStatusCode::TOO_MANY_REQUESTS) {
3434
return true;
3535
}
36+
37+
if (response.status == static_cast<int>(http::ErrorCode::IO_ERROR) ||
38+
response.status == static_cast<int>(http::ErrorCode::OFFLINE_ERROR) ||
39+
response.status == static_cast<int>(http::ErrorCode::TIMEOUT_ERROR) ||
40+
response.status ==
41+
static_cast<int>(http::ErrorCode::NETWORK_OVERLOAD_ERROR)) {
42+
return true;
43+
}
3644
return false;
3745
}
3846

olp-cpp-sdk-core/tests/client/OlpClientTest.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,10 +252,11 @@ TEST_P(OlpClientTest, DefaultRetryCondition) {
252252
olp::http::RequestId request_id = 5;
253253
std::vector<std::future<void>> futures;
254254

255-
// retry for 429 and all 5xx status codes.
255+
// retry for IO, offline, timeout, network overload error codes and 429, all
256+
// 5xx http status codes.
256257
auto attempt_statuses =
257-
std::queue<int>{{429, 500, 501, 502, 503, 504, 505, 506, 507, 508, 509,
258-
510, 511, 598, 599, 200}};
258+
std::queue<int>{{-1, -4, -7, -8, 429, 500, 501, 502, 503, 504,
259+
505, 506, 507, 508, 509, 510, 511, 598, 599, 200}};
259260
client_settings_.retry_settings.max_attempts = attempt_statuses.size();
260261
client_settings_.retry_settings.backdown_strategy =
261262
[](std::chrono::milliseconds, size_t) {
@@ -1547,6 +1548,7 @@ TEST_P(OlpClientTest, CancelRetry) {
15471548

15481549
TEST_P(OlpClientTest, SlowDownError) {
15491550
auto network = network_;
1551+
client_settings_.retry_settings.max_attempts = 0;
15501552
client_.SetSettings(client_settings_);
15511553
constexpr int kExpectedError =
15521554
static_cast<int>(http::ErrorCode::NETWORK_OVERLOAD_ERROR);

0 commit comments

Comments
 (0)