Skip to content

Commit cdf9b95

Browse files
LeoPatOZ0xNeshi
andauthored
Update src/safe_provider.rs
Co-authored-by: Nenad <nenad.misic@openzeppelin.com>
1 parent 992853c commit cdf9b95

File tree

1 file changed

+13
-20
lines changed

1 file changed

+13
-20
lines changed

src/safe_provider.rs

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -226,41 +226,34 @@ mod tests {
226226
use std::sync::{Arc, Mutex};
227227
use tokio::time::sleep;
228228

229-
fn create_test_provider(
230-
timeout: Duration,
229+
fn test_provider(
230+
timeout: u64,
231231
max_retries: usize,
232-
retry_interval: Duration,
232+
retry_interval: u64,
233233
) -> SafeProvider<Ethereum> {
234234
SafeProvider {
235-
provider: RootProvider::<Ethereum>::new_http("http://localhost:8545".parse().unwrap()),
236-
max_timeout: timeout,
235+
provider: RootProvider::new_http("http://localhost:8545".parse().unwrap()),
236+
max_timeout: Duration::from_millis(timeout),
237237
max_retries,
238-
retry_interval,
238+
retry_interval: Duration::from_millis(retry_interval),
239239
}
240240
}
241241

242242
#[tokio::test]
243243
async fn test_retry_with_timeout_succeeds_on_first_attempt() {
244-
let provider =
245-
create_test_provider(Duration::from_millis(100), 3, Duration::from_millis(10));
244+
let provider = test_provider(100, 3, 10);
246245

247-
let call_count = Arc::new(Mutex::new(0));
248-
let call_count_clone = call_count.clone();
246+
let call_count = AtomicUsize::new(0);
249247

250248
let result = provider
251-
.retry_with_total_timeout(move || {
252-
let count = call_count_clone.clone();
253-
async move {
254-
let mut c = count.lock().unwrap();
255-
*c += 1;
256-
Ok(42)
257-
}
249+
.retry_with_timeout(|| async {
250+
call_count.fetch_add(1, Ordering::SeqCst);
251+
Ok(42)
258252
})
259253
.await;
260254

261-
assert!(result.is_ok());
262-
assert_eq!(result.unwrap(), 42);
263-
assert_eq!(*call_count.lock().unwrap(), 1);
255+
assert!(matches!(result, Ok(42)));
256+
assert_eq!(call_count.load(Ordering::SeqCst), 1);
264257
}
265258

266259
#[tokio::test]

0 commit comments

Comments
 (0)