Skip to content

Commit b77db7c

Browse files
authored
fix(store): Get the activation with the earliest added_at when get_pending_activation (#73)
1 parent b221083 commit b77db7c

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/inflight_activation_store.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ impl InflightActivationStore {
203203
FROM inflight_taskactivations
204204
WHERE status = $2
205205
AND (deadletter_at IS NULL OR deadletter_at > $3)
206+
ORDER BY added_at
206207
LIMIT 1
207208
)
208209
RETURNING *",
@@ -628,6 +629,23 @@ mod tests {
628629
assert_count_by_status(&store, InflightActivationStatus::Pending, 1).await;
629630
}
630631

632+
#[tokio::test]
633+
async fn test_get_pending_activation_earliest() {
634+
let url = generate_temp_filename();
635+
let store = InflightActivationStore::new(&url).await.unwrap();
636+
637+
let mut batch = make_activations(2);
638+
batch[0].added_at = Utc.with_ymd_and_hms(2024, 6, 24, 0, 0, 0).unwrap();
639+
batch[1].added_at = Utc.with_ymd_and_hms(1998, 6, 24, 0, 0, 0).unwrap();
640+
assert!(store.store(batch.clone()).await.is_ok());
641+
642+
let result = store.get_pending_activation().await.unwrap().unwrap();
643+
assert_eq!(
644+
result.added_at,
645+
Utc.with_ymd_and_hms(1998, 6, 24, 0, 0, 0).unwrap()
646+
);
647+
}
648+
631649
#[tokio::test]
632650
async fn test_count_pending_activations() {
633651
let url = generate_temp_filename();

0 commit comments

Comments
 (0)