Skip to content

Commit b8679e5

Browse files
committed
feat: test for Circuit Breaker Retry Logic
1 parent 97e182e commit b8679e5

File tree

1 file changed

+12
-6
lines changed
  • crates/web-plugins/didcomm-messaging/shared/src/breaker

1 file changed

+12
-6
lines changed

crates/web-plugins/didcomm-messaging/shared/src/breaker/tests.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,25 @@ async fn test_retry_configuration() {
6161
let breaker = CircuitBreaker::new().retries(2);
6262

6363
let attempts = Arc::new(AtomicUsize::new(0));
64-
let attempts = attempts.clone();
65-
66-
let retry_operation = || async {
67-
attempts.fetch_add(1, Ordering::AcqRel);
68-
async { Err::<(), ()>(()) }.await
64+
let attempts_clone = attempts.clone();
65+
66+
let retry_operation = || {
67+
let attempts = attempts_clone.clone();
68+
async move {
69+
attempts.fetch_add(1, Ordering::AcqRel);
70+
Err::<(), ()>(()) // Simulate a failure
71+
}
6972
};
7073

7174
let result = breaker.call(retry_operation).await;
75+
76+
// Verify the result matches the expected error type
7277
assert!(matches!(result, Err(Error::Inner(_))));
73-
// the total number of attempts should be 2
78+
// Verify that the total number of attempts was 2
7479
assert_eq!(attempts.load(Ordering::Relaxed), 2);
7580
}
7681

82+
7783
#[tokio::test]
7884
async fn test_timeout_reset() {
7985
let breaker = CircuitBreaker::new().reset_timeout(Duration::from_millis(100));

0 commit comments

Comments
 (0)