Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

259 write tests to validate reliability features eg simulated network failures retries e3 #284

Open
wants to merge 57 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
6ceb8f1
feat: reliability features doc
Blindspot22 Dec 6, 2024
310f645
feat: realibity tests
Blindspot22 Dec 6, 2024
d1b18c0
feat: realibity tests
Blindspot22 Dec 6, 2024
c83a763
feat: realibity tests
Blindspot22 Dec 6, 2024
e334959
feat: realibity tests update
Blindspot22 Dec 6, 2024
3ca1cda
feat: ci renaming
Blindspot22 Dec 6, 2024
7827e81
feat: added a trigger and if condition to proceed with deployment onl…
Blindspot22 Dec 6, 2024
4911bba
feat: added a trigger and if condition to proceed with deployment onl…
Blindspot22 Dec 6, 2024
a7d3330
feat: added a trigger and if condition to proceed with deployment onl…
Blindspot22 Dec 6, 2024
2e3f2ba
feat: added a trigger and if condition to proceed with deployment onl…
Blindspot22 Dec 6, 2024
2f04e61
feat: added a trigger and if condition to proceed with deployment onl…
Blindspot22 Dec 6, 2024
bf4dece
feat: adjusting realibity tests
Blindspot22 Dec 6, 2024
8807fed
feat: adjusting realibity tests
Blindspot22 Dec 6, 2024
afa84d8
feat: adjusting realibity tests
Blindspot22 Dec 6, 2024
bea24df
feat: simulation of network failures
Blindspot22 Dec 6, 2024
277ecbc
feat: message acknowledgment
Blindspot22 Dec 6, 2024
c499859
feat: retry logic
Blindspot22 Dec 6, 2024
a2e2181
feat: test(network_timeout, retry_logic, message_acknowledgement)
Blindspot22 Dec 6, 2024
f491b6c
fix: deleted files
Blindspot22 Dec 6, 2024
4a6a469
reliabitytest
Blindspot22 Dec 12, 2024
f7e0e20
discard unusefull test
Blindspot22 Dec 12, 2024
13c6cef
Merge remote-tracking branch 'origin' into 259-write-tests-to-validat…
Blindspot22 Dec 16, 2024
d367dc7
nexttest.toml
Blindspot22 Dec 16, 2024
926c3f4
update nextest.toml
Blindspot22 Dec 16, 2024
1e86dc0
update CI.yml
Blindspot22 Dec 16, 2024
8bfb227
fix: update CI.yml
Blindspot22 Dec 19, 2024
442694d
feat: refactoring based on reviews
Blindspot22 Jan 21, 2025
e8962fa
feat: refactor based on reviews
Blindspot22 Jan 21, 2025
388e809
fix: deleted nextest.toml file
Blindspot22 Jan 21, 2025
d46e965
feat: ammeliorating test
Blindspot22 Jan 21, 2025
9f7b15b
feat: test_exponential_backoff
Blindspot22 Jan 21, 2025
e5fd44c
feat: test_queue_overflow_handling
Blindspot22 Jan 21, 2025
15a4cd7
feat: test_concurrent_message_processing
Blindspot22 Jan 21, 2025
f607a1c
feat: test_out_of_order_message_recovery
Blindspot22 Jan 21, 2025
b0a26e4
feat: updated reliability-features.md
Blindspot22 Jan 21, 2025
b5be45c
feat: update CI to match new tests
Blindspot22 Jan 21, 2025
664d9be
feat: update CD to match new tests
Blindspot22 Jan 21, 2025
ebc5885
feat: recent fixes based on implementation guide
Blindspot22 Jan 28, 2025
168490a
fix: test fixes
Blindspot22 Jan 28, 2025
6902259
feat: new fixes, removed CD.yml
Blindspot22 Jan 28, 2025
2ea7905
feat: Resolving Conflicts
Blindspot22 Feb 4, 2025
75bcd45
Update CI.yml
Blindspot22 Feb 4, 2025
1850bd2
Update CI.yml
Blindspot22 Feb 4, 2025
30586ad
Update CI.yml
Blindspot22 Feb 4, 2025
9623cfe
fix: adjusting test failure
Blindspot22 Feb 4, 2025
7e38722
Merge branch '259-write-tests-to-validate-reliability-features-eg-sim…
Blindspot22 Feb 4, 2025
ab60446
feat: addeded mock-service for mediator
Blindspot22 Feb 6, 2025
e732691
feat: retry mechanism
Blindspot22 Feb 6, 2025
bec7b9c
feat: reliability_test implementation
Blindspot22 Feb 6, 2025
05931a1
feat: removed old test due to malfunction
Blindspot22 Feb 6, 2025
79a69ec
feat: mock service implementation
Blindspot22 Feb 6, 2025
96d095c
feat: reliability implementation for mediator
Blindspot22 Feb 6, 2025
4d97947
feat: retry mechanism
Blindspot22 Feb 6, 2025
ce28bb2
feat: update main.rs and Cargo.toml to match with new changes
Blindspot22 Feb 6, 2025
0d45f39
feat: added rebiality_test into CI.yml
Blindspot22 Feb 6, 2025
c6b6a23
feat: update CI.yml
Blindspot22 Feb 6, 2025
f6f8fe8
fix: update CI.yml
Blindspot22 Feb 7, 2025
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
20 changes: 0 additions & 20 deletions .github/workflows/CD.yml

This file was deleted.

6 changes: 5 additions & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,8 @@ jobs:
cargo clippy --workspace --all-targets --all-features -- -D warnings

- name: Check API documentation
run: cargo doc --workspace --all-features --no-deps
run: cargo doc --workspace --all-features --no-deps

- name: Run Reliability Tests
run: cargo nextest run --workspace --all-features --filterset "test(reliability)"

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ did-endpoint = { workspace = true, optional = true }
oob-messages = { workspace = true, optional = true }
didcomm-messaging = { workspace = true, optional = true }
reqwest.workspace = true
uuid.workspace = true
tokio-retry = "0.3.0"



Expand Down
22 changes: 22 additions & 0 deletions docs/reliability-features.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Documented Test Cases and Results
### Implementation Status:
- **✅:** Fully implemented and passing.
- **⚪:** In progress or partially implemented.
- **❌:** Not yet implemented.

| **Test Case** | **Description** | **Expected Outcome** | **Implementation Status** |
|----------------------------------------|---------------------------------------------------------------------------------|--------------------------------------------------|---------------------------|
| **test_retry_logic_on_intermittent_connectivity** | Validate retry mechanism under network interruptions. | Retries the message and delivers successfully. | ✅ |
| **Retry Logic with Timeout** | Verify that retries stop after the maximum configured limit. | Stops retries after 3 attempts. | ✅ |
| **Message Acknowledgment Validation** | Ensure acknowledgment is sent upon successful delivery of a message. | Acknowledgment is sent correctly. | ✅ |
| **Concurrent Message Processing** | Test mediator's ability to handle multiple concurrent message processing tasks. | All messages are processed without failures. | ✅ |
| **Message Delivery Confirmation** | Confirm that delivery status is tracked correctly. | Tracks and confirms delivery of all messages. | ⚪ |
| **Exponential Backoff Strategy** | Validate exponential backoff timing during retries. | Backoff increases exponentially with each retry. | ❌ |
| **Connection Timeout Handling** | Test mediator behavior when connection timeouts occur. | Fails gracefully and retries within set limits. | ❌ |
| **Queue Overflow Handling** | Validate the handling of message queue overflow scenarios. | Ensures no data loss and processes in order. | ✅ |
| **Out-of-Order Message Recovery** | Test ability to recover and process messages received out of order. | Processes all messages in correct sequence. | ✅ |
| **Broken Pipe Recovery** | Validate recovery mechanism when a broken pipe error occurs. | Reestablishes connection and retries seamlessly. | ⚪ |

---


39 changes: 32 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,33 @@ use eyre::{Result, WrapErr};
use std::net::SocketAddr;
use tokio::net::TcpListener;

use reqwest::{Client, StatusCode};
use thiserror::Error;
use tokio_retry::strategy::ExponentialBackoff;
use tokio_retry::Retry;

#[derive(Error, Debug)]
pub enum FetchError {
#[error("Request failed with status {0}")]
RequestFailed(StatusCode),
#[error("HTTP client error: {0}")]
ClientError(#[from] reqwest::Error),
}

pub async fn fetch_with_retries(client: &Client, url: &str) -> Result<String, FetchError> {
let retry_strategy = ExponentialBackoff::from_millis(100).take(3);

Retry::spawn(retry_strategy, || async {
let response = client.get(url).send().await?;
if response.status().is_success() {
Ok(response.text().await?)
} else {
Err(FetchError::RequestFailed(response.status()))
}
})
.await
}

#[tokio::main]
async fn main() -> Result<()> {
// Load dotenv-flow variables
Expand All @@ -17,7 +44,7 @@ async fn main() -> Result<()> {
let addr = SocketAddr::from(([0, 0, 0, 0], port));
let listener = TcpListener::bind(addr)
.await
.context("failed to parse address")?;
.context("failed to bind address")?;

tracing::debug!("listening on {addr}");

Expand Down Expand Up @@ -70,10 +97,10 @@ fn config_tracing() {
.with(filter)
.init();
}
#[cfg(test)]

#[cfg(test)]
mod test {

use super::*;
use reqwest::Client;
use tokio::{task, time::Instant};

Expand All @@ -84,15 +111,14 @@ mod test {
let num_requests = 1000;

let mut handles = Vec::new();

let start = Instant::now();

for _ in 0..num_requests {
let client = client.clone();
let url = url.to_string();

let handle = task::spawn(async move {
match client.get(&url).send().await {
match fetch_with_retries(&client, &url).await {
Ok(_resp) => (),
Err(e) => panic!("{}", e),
}
Expand All @@ -102,8 +128,7 @@ mod test {
}

for handle in handles {
let a = handle.await;
if let Err(e) = a {
if let Err(e) = handle.await {
panic!("{}", e)
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/tests/mock_service.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use mockito::{mock, Mock};

pub fn setup_mock_service() -> Mock {
mock("GET", "/upstream")
.with_status(503)
.with_body("Service Unavailable")
.create()
}
41 changes: 41 additions & 0 deletions src/tests/reliability_tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#[cfg(test)]
mod tests {
use crate::mediator::fetch_with_retries;
use crate::tests::mock_service::setup_mock_service;
use mockito::server_url;
use reqwest::Client;

#[tokio::test]
async fn test_mediator_retries_on_upstream_failure() {
// Setup mock upstream service
let _mock = setup_mock_service();

// Mediator client
let client = Client::new();
let url = format!("{}/upstream", server_url());

// Test fetch with retries
let result = fetch_with_retries(&client, &url).await;
assert!(result.is_err(), "Expected retries to fail after all attempts");
}

#[tokio::test]
async fn test_mediator_fallback_on_upstream_failure() {
// Setup mock upstream service
let _mock = setup_mock_service();

// Fallback data
let fallback_data = "Fallback response".to_string();

// Mediator client
let client = Client::new();
let url = format!("{}/upstream", server_url());

// Fetch with retries and fallback
let result = fetch_with_retries(&client, &url)
.await
.unwrap_or(fallback_data.clone());

assert_eq!(result, fallback_data, "Expected fallback response on failure");
}
}
7 changes: 7 additions & 0 deletions src/tests/retry.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use reqwest::Client;
use reqwest::Error;

pub async fn test_retry_logic(client: &Client, url: &str) -> Result<String, Error> {
// Sample retry logic for validation
Ok(client.get(url).send().await?.text().await?)
}
Loading