Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: I082de335ed2b2bf53d687d81db0901ef6a6a6964
121 lines
3.2 KiB
Rust
121 lines
3.2 KiB
Rust
//! Retry logic integration tests.
|
|
#![expect(clippy::expect_used)]
|
|
|
|
use std::sync::{
|
|
Arc,
|
|
atomic::{AtomicUsize, Ordering},
|
|
};
|
|
|
|
use konservejo::core::pipeline::Pipeline;
|
|
use wiremock::{
|
|
Mock,
|
|
MockServer,
|
|
ResponseTemplate,
|
|
matchers::{header, method, path_regex},
|
|
};
|
|
|
|
mod common;
|
|
use common::{
|
|
MockRepo,
|
|
TestContext,
|
|
create_test_archive,
|
|
load_config,
|
|
setup_mock_server,
|
|
};
|
|
|
|
#[tokio::test]
|
|
async fn test_no_retry_on_not_found() {
|
|
let request_count = Arc::new(AtomicUsize::new(0));
|
|
|
|
let server = MockServer::start().await;
|
|
|
|
let count = Arc::clone(&request_count);
|
|
Mock::given(method("GET"))
|
|
.and(path_regex("/orgs/test-org/repos.*"))
|
|
.and(header("authorization", "token test-token"))
|
|
.respond_with(move |_req: &wiremock::Request| {
|
|
count.fetch_add(1, Ordering::SeqCst);
|
|
ResponseTemplate::new(404)
|
|
})
|
|
.mount(&server)
|
|
.await;
|
|
|
|
let ctx = TestContext::new(server.uri());
|
|
ctx.write_config(&["test-org".to_string()], &[], 4, 5, 10);
|
|
|
|
let config = load_config(&ctx).expect("Failed to load config");
|
|
let pipeline = Pipeline::new(config)
|
|
.await
|
|
.expect("Failed to create pipeline");
|
|
|
|
let result = pipeline.run().await;
|
|
|
|
assert!(result.is_err(), "Should fail with 404");
|
|
assert_eq!(
|
|
request_count.load(Ordering::SeqCst),
|
|
1,
|
|
"Should not retry on 404 (only makes 1 request)"
|
|
);
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn test_backup_with_multiple_repos() {
|
|
let archive1 = create_test_archive("repo1");
|
|
let archive2 = create_test_archive("repo2");
|
|
|
|
let repos = vec![
|
|
MockRepo::new("test-org", "repo1", archive1),
|
|
MockRepo::new("test-org", "repo2", archive2),
|
|
];
|
|
let (_server, mock_url) = setup_mock_server(repos).await;
|
|
|
|
let ctx = TestContext::new(mock_url);
|
|
ctx.write_config(&["test-org".to_string()], &[], 4, 1, 10);
|
|
|
|
let config = load_config(&ctx).expect("Failed to load config");
|
|
let pipeline = Pipeline::new(config)
|
|
.await
|
|
.expect("Failed to create pipeline");
|
|
|
|
let run_id = pipeline.run().await.expect("Backup failed");
|
|
|
|
let db_url = format!("sqlite://{}", ctx.db_path().display());
|
|
let storage = konservejo::storage::Storage::new(&db_url)
|
|
.await
|
|
.expect("Failed to connect to DB");
|
|
let jobs = storage
|
|
.list_jobs_by_run(&run_id)
|
|
.await
|
|
.expect("Failed to list jobs");
|
|
|
|
assert_eq!(jobs.len(), 2, "Should have 2 jobs");
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn test_backup_single_repo() {
|
|
let archive = create_test_archive("single-repo");
|
|
|
|
let repos = vec![MockRepo::new("test-org", "repo1", archive)];
|
|
let (_server, mock_url) = setup_mock_server(repos).await;
|
|
|
|
let ctx = TestContext::new(mock_url);
|
|
ctx.write_config(&["test-org".to_string()], &[], 4, 1, 10);
|
|
|
|
let config = load_config(&ctx).expect("Failed to load config");
|
|
let pipeline = Pipeline::new(config)
|
|
.await
|
|
.expect("Failed to create pipeline");
|
|
|
|
let run_id = pipeline.run().await.expect("Backup failed");
|
|
|
|
let db_url = format!("sqlite://{}", ctx.db_path().display());
|
|
let storage = konservejo::storage::Storage::new(&db_url)
|
|
.await
|
|
.expect("Failed to connect to DB");
|
|
let jobs = storage
|
|
.list_jobs_by_run(&run_id)
|
|
.await
|
|
.expect("Failed to list jobs");
|
|
|
|
assert_eq!(jobs.len(), 1, "Should have 1 job");
|
|
}
|