Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions reqwest-retry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions reqwest-retry/src/middleware.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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;
Expand Down
34 changes: 17 additions & 17 deletions reqwest-retry/tests/all/retry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
))
Expand Down Expand Up @@ -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<AtomicU32>, u32, std::time::Duration);
pub struct RetryTimeoutResponder(Arc<AtomicU32>, 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)
}
}
Expand All @@ -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)
Expand All @@ -191,16 +191,16 @@ 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),
))
.build();

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");
Expand Down Expand Up @@ -246,16 +246,16 @@ 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),
))
.build();

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");
Expand Down Expand Up @@ -297,16 +297,16 @@ 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),
))
.build();

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");
Expand Down Expand Up @@ -345,16 +345,16 @@ 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),
))
.build();

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");
Expand Down
Loading