@@ -182,3 +182,40 @@ TEST_CASE(
182182 const auto & extra_headers = resources.rest_client ()->extra_headers ();
183183 CHECK (extra_headers.at (" X-Payer" ) == " foo" );
184184}
185+
186+ TEST_CASE (" Test retry logic" , " [rest-client][retries]" ) {
187+ // set the HTTP codes to retry
188+ tiledb::sm::Config cfg;
189+ REQUIRE (cfg.set (" rest.retry_http_codes" , " 503" ).ok ());
190+
191+ std::unordered_map<std::string, std::string> extra_headers;
192+ std::unordered_map<std::string, std::string> res_headers;
193+ std::mutex res_mtx;
194+ Curl curl (tiledb::test::g_helper_logger ());
195+ auto rc = curl.init (&cfg, extra_headers, &res_headers, &res_mtx);
196+
197+ // http error not in retry list
198+ CURLcode curl_code = CURLE_OK;
199+ long http_code = 504 ;
200+ REQUIRE (curl.should_retry_request (curl_code, http_code) == false );
201+
202+ // http error in retry list
203+ http_code = 503 ;
204+ REQUIRE (curl.should_retry_request (curl_code, http_code) == true );
205+
206+ // Curl error not in retry list
207+ curl_code = CURLE_SSL_SHUTDOWN_FAILED;
208+ REQUIRE (curl.should_retry_request (curl_code, http_code) == false );
209+
210+ // Curl error in retry list
211+ curl_code = CURLE_RECV_ERROR;
212+ // and http error not in retry list
213+ http_code = 504 ;
214+ REQUIRE (curl.should_retry_request (curl_code, http_code) == true );
215+
216+ // Curl error in retry list but retries disabled in config
217+ REQUIRE (cfg.set (" rest.curl.retry_errors" , " false" ).ok ());
218+ rc = curl.init (&cfg, extra_headers, &res_headers, &res_mtx);
219+ curl_code = CURLE_RECV_ERROR;
220+ REQUIRE (curl.should_retry_request (curl_code, http_code) == false );
221+ }
0 commit comments