diff --git a/src/inflight_activation_store.rs b/src/inflight_activation_store.rs index 0a470089..f39df7ce 100644 --- a/src/inflight_activation_store.rs +++ b/src/inflight_activation_store.rs @@ -203,6 +203,7 @@ impl InflightActivationStore { FROM inflight_taskactivations WHERE status = $2 AND (deadletter_at IS NULL OR deadletter_at > $3) + ORDER BY added_at LIMIT 1 ) RETURNING *", @@ -628,6 +629,23 @@ mod tests { assert_count_by_status(&store, InflightActivationStatus::Pending, 1).await; } + #[tokio::test] + async fn test_get_pending_activation_earliest() { + let url = generate_temp_filename(); + let store = InflightActivationStore::new(&url).await.unwrap(); + + let mut batch = make_activations(2); + batch[0].added_at = Utc.with_ymd_and_hms(2024, 6, 24, 0, 0, 0).unwrap(); + batch[1].added_at = Utc.with_ymd_and_hms(1998, 6, 24, 0, 0, 0).unwrap(); + assert!(store.store(batch.clone()).await.is_ok()); + + let result = store.get_pending_activation().await.unwrap().unwrap(); + assert_eq!( + result.added_at, + Utc.with_ymd_and_hms(1998, 6, 24, 0, 0, 0).unwrap() + ); + } + #[tokio::test] async fn test_count_pending_activations() { let url = generate_temp_filename();