From 95f2cc034ac07caef39b02900d5d074af836376e Mon Sep 17 00:00:00 2001 From: Dickless <011001nobuo@gmail.com> Date: Mon, 28 Jul 2025 18:36:00 +0900 Subject: [PATCH] feat: replace std::time with web_time --- reqwest-retry/Cargo.toml | 1 + reqwest-retry/src/middleware.rs | 4 ++-- reqwest-retry/tests/all/retry.rs | 34 ++++++++++++++++---------------- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/reqwest-retry/Cargo.toml b/reqwest-retry/Cargo.toml index 9ebfd12..1693d4a 100644 --- a/reqwest-retry/Cargo.toml +++ b/reqwest-retry/Cargo.toml @@ -24,6 +24,7 @@ reqwest = { version = "0.12.0", default-features = false } retry-policies = "0.4" thiserror = "1.0.61" tracing = { version = "0.1.26", optional = true } +web-time = "1.1.0" [target.'cfg(not(target_arch = "wasm32"))'.dependencies] hyper = "1.0" diff --git a/reqwest-retry/src/middleware.rs b/reqwest-retry/src/middleware.rs index a8339c1..e59d51e 100644 --- a/reqwest-retry/src/middleware.rs +++ b/reqwest-retry/src/middleware.rs @@ -1,5 +1,5 @@ //! `RetryTransientMiddleware` implements retrying requests on transient errors. -use std::time::{Duration, SystemTime}; +use web_time::{Duration, SystemTime}; use crate::retryable_strategy::RetryableStrategy; use crate::{retryable::Retryable, retryable_strategy::DefaultRetryableStrategy, RetryError}; @@ -34,7 +34,7 @@ macro_rules! log_retry { /// runtime that supports them. /// ///```rust -/// use std::time::Duration; +/// use web_time::Duration; /// use reqwest_middleware::ClientBuilder; /// use retry_policies::{RetryDecision, RetryPolicy, Jitter}; /// use retry_policies::policies::ExponentialBackoff; diff --git a/reqwest-retry/tests/all/retry.rs b/reqwest-retry/tests/all/retry.rs index 15744a9..4c851ee 100644 --- a/reqwest-retry/tests/all/retry.rs +++ b/reqwest-retry/tests/all/retry.rs @@ -55,8 +55,8 @@ macro_rules! assert_retry_succeeds_inner { .with(RetryTransientMiddleware::new_with_policy( ExponentialBackoff::builder() .retry_bounds( - std::time::Duration::from_millis(30), - std::time::Duration::from_millis(100), + web_time::Duration::from_millis(30), + web_time::Duration::from_millis(100), ) .build_with_max_retries(retry_amount), )) @@ -151,10 +151,10 @@ assert_retry_succeeds!(429, StatusCode::OK); assert_no_retry!(431, StatusCode::REQUEST_HEADER_FIELDS_TOO_LARGE); assert_no_retry!(451, StatusCode::UNAVAILABLE_FOR_LEGAL_REASONS); -pub struct RetryTimeoutResponder(Arc, u32, std::time::Duration); +pub struct RetryTimeoutResponder(Arc, u32, web_time::Duration); impl RetryTimeoutResponder { - fn new(retries: u32, initial_timeout: std::time::Duration) -> Self { + fn new(retries: u32, initial_timeout: web_time::Duration) -> Self { Self(Arc::new(AtomicU32::new(0)), retries, initial_timeout) } } @@ -180,7 +180,7 @@ async fn assert_retry_on_request_timeout() { .and(path("/foo")) .respond_with(RetryTimeoutResponder::new( 3, - std::time::Duration::from_millis(1000), + web_time::Duration::from_millis(1000), )) .expect(2) .mount(&server) @@ -191,8 +191,8 @@ async fn assert_retry_on_request_timeout() { .with(RetryTransientMiddleware::new_with_policy( ExponentialBackoff::builder() .retry_bounds( - std::time::Duration::from_millis(30), - std::time::Duration::from_millis(100), + web_time::Duration::from_millis(30), + web_time::Duration::from_millis(100), ) .build_with_max_retries(3), )) @@ -200,7 +200,7 @@ async fn assert_retry_on_request_timeout() { let resp = client .get(format!("{}/foo", server.uri())) - .timeout(std::time::Duration::from_millis(10)) + .timeout(web_time::Duration::from_millis(10)) .send() .await .expect("call failed"); @@ -246,8 +246,8 @@ async fn assert_retry_on_incomplete_message() { .with(RetryTransientMiddleware::new_with_policy( ExponentialBackoff::builder() .retry_bounds( - std::time::Duration::from_millis(30), - std::time::Duration::from_millis(100), + web_time::Duration::from_millis(30), + web_time::Duration::from_millis(100), ) .build_with_max_retries(3), )) @@ -255,7 +255,7 @@ async fn assert_retry_on_incomplete_message() { let resp = client .get(format!("{}/foo", uri)) - .timeout(std::time::Duration::from_millis(100)) + .timeout(web_time::Duration::from_millis(100)) .send() .await .expect("call failed"); @@ -297,8 +297,8 @@ async fn assert_retry_on_hyper_canceled() { .with(RetryTransientMiddleware::new_with_policy( ExponentialBackoff::builder() .retry_bounds( - std::time::Duration::from_millis(30), - std::time::Duration::from_millis(100), + web_time::Duration::from_millis(30), + web_time::Duration::from_millis(100), ) .build_with_max_retries(3), )) @@ -306,7 +306,7 @@ async fn assert_retry_on_hyper_canceled() { let resp = client .get(format!("{}/foo", uri)) - .timeout(std::time::Duration::from_millis(100)) + .timeout(web_time::Duration::from_millis(100)) .send() .await .expect("call failed"); @@ -345,8 +345,8 @@ async fn assert_retry_on_connection_reset_by_peer() { .with(RetryTransientMiddleware::new_with_policy( ExponentialBackoff::builder() .retry_bounds( - std::time::Duration::from_millis(30), - std::time::Duration::from_millis(100), + web_time::Duration::from_millis(30), + web_time::Duration::from_millis(100), ) .build_with_max_retries(3), )) @@ -354,7 +354,7 @@ async fn assert_retry_on_connection_reset_by_peer() { let resp = client .get(format!("{}/foo", uri)) - .timeout(std::time::Duration::from_millis(100)) + .timeout(web_time::Duration::from_millis(100)) .send() .await .expect("call failed");