feat: processed-event ledger, idempotent dispatch
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
use application::jobs::{PROCESSED_EVENTS_RETENTION_DAYS, ProcessedEventsCleanupJob};
|
||||
use domain::{events::EventId, ports::PeriodicJob, testing::InMemoryStore};
|
||||
|
||||
#[tokio::test]
|
||||
async fn removes_only_rows_older_than_the_retention_window() {
|
||||
let store = InMemoryStore::new();
|
||||
let now = chrono::Utc::now().naive_utc();
|
||||
let stale = EventId::new();
|
||||
let fresh = EventId::new();
|
||||
store.seed_processed_event(
|
||||
&stale,
|
||||
"h",
|
||||
now - chrono::Duration::days(PROCESSED_EVENTS_RETENTION_DAYS + 1),
|
||||
);
|
||||
store.seed_processed_event(
|
||||
&fresh,
|
||||
"h",
|
||||
now - chrono::Duration::days(PROCESSED_EVENTS_RETENTION_DAYS - 1),
|
||||
);
|
||||
|
||||
ProcessedEventsCleanupJob::new(store.clone())
|
||||
.run()
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
use domain::ports::ProcessedEventLedger;
|
||||
assert!(!store.has_processed(&stale, "h").await.unwrap());
|
||||
assert!(store.has_processed(&fresh, "h").await.unwrap());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn runs_daily() {
|
||||
let job = ProcessedEventsCleanupJob::new(InMemoryStore::new());
|
||||
assert_eq!(job.interval(), std::time::Duration::from_secs(86_400));
|
||||
}
|
||||
Reference in New Issue
Block a user