Fix pagination by anchor for queued messages, tasks and metrics
This commit is contained in:
@@ -25,6 +25,7 @@ use registry::{
|
||||
};
|
||||
use serde_json::json;
|
||||
use std::time::{Duration, Instant};
|
||||
use types::id::Id;
|
||||
|
||||
#[tokio::test]
|
||||
#[serial_test::serial]
|
||||
@@ -335,6 +336,110 @@ async fn manage_queue() {
|
||||
);
|
||||
}
|
||||
|
||||
// Test pagination (forward and reverse)
|
||||
let asc_order: Vec<Id> = admin
|
||||
.registry_query_paginated(
|
||||
ObjectType::QueuedMessage,
|
||||
"due",
|
||||
true,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
false,
|
||||
)
|
||||
.await
|
||||
.object_ids()
|
||||
.collect();
|
||||
assert_eq!(asc_order.len(), 6, "expected 6 messages, got {asc_order:?}");
|
||||
let desc_order: Vec<Id> = asc_order.iter().rev().copied().collect();
|
||||
|
||||
for chunk_start in [0usize, 2, 4] {
|
||||
let asc = admin
|
||||
.registry_query_paginated(
|
||||
ObjectType::QueuedMessage,
|
||||
"due",
|
||||
true,
|
||||
Some(chunk_start as i32),
|
||||
Some(2),
|
||||
None,
|
||||
None,
|
||||
false,
|
||||
)
|
||||
.await
|
||||
.object_ids()
|
||||
.collect::<Vec<_>>();
|
||||
assert_eq!(
|
||||
asc,
|
||||
asc_order[chunk_start..chunk_start + 2],
|
||||
"ascending position={chunk_start} limit=2",
|
||||
);
|
||||
|
||||
let desc = admin
|
||||
.registry_query_paginated(
|
||||
ObjectType::QueuedMessage,
|
||||
"due",
|
||||
false,
|
||||
Some(chunk_start as i32),
|
||||
Some(2),
|
||||
None,
|
||||
None,
|
||||
false,
|
||||
)
|
||||
.await
|
||||
.object_ids()
|
||||
.collect::<Vec<_>>();
|
||||
assert_eq!(
|
||||
desc,
|
||||
desc_order[chunk_start..chunk_start + 2],
|
||||
"descending position={chunk_start} limit=2",
|
||||
);
|
||||
}
|
||||
|
||||
for anchor_idx in [1usize, 3] {
|
||||
let asc = admin
|
||||
.registry_query_paginated(
|
||||
ObjectType::QueuedMessage,
|
||||
"due",
|
||||
true,
|
||||
None,
|
||||
Some(2),
|
||||
Some(asc_order[anchor_idx]),
|
||||
Some(1),
|
||||
false,
|
||||
)
|
||||
.await
|
||||
.object_ids()
|
||||
.collect::<Vec<_>>();
|
||||
assert_eq!(
|
||||
asc,
|
||||
asc_order[anchor_idx + 1..anchor_idx + 3],
|
||||
"ascending anchor={} offset=1 limit=2",
|
||||
asc_order[anchor_idx],
|
||||
);
|
||||
|
||||
let desc = admin
|
||||
.registry_query_paginated(
|
||||
ObjectType::QueuedMessage,
|
||||
"due",
|
||||
false,
|
||||
None,
|
||||
Some(2),
|
||||
Some(desc_order[anchor_idx]),
|
||||
Some(1),
|
||||
false,
|
||||
)
|
||||
.await
|
||||
.object_ids()
|
||||
.collect::<Vec<_>>();
|
||||
assert_eq!(
|
||||
desc,
|
||||
desc_order[anchor_idx + 1..anchor_idx + 3],
|
||||
"descending anchor={} offset=1 limit=2",
|
||||
desc_order[anchor_idx],
|
||||
);
|
||||
}
|
||||
|
||||
// Retry delivery
|
||||
admin
|
||||
.registry_update_object(
|
||||
|
||||
Reference in New Issue
Block a user