Fix pagination by anchor for queued messages, tasks and metrics
This commit is contained in:
@@ -72,6 +72,114 @@ pub async fn test(test: &TestServer) {
|
||||
metric_ids.len()
|
||||
);
|
||||
|
||||
// Test pagination (forward and reverse)
|
||||
let asc_order: Vec<Id> = admin
|
||||
.registry_query_paginated(
|
||||
ObjectType::Metric,
|
||||
"timestamp",
|
||||
true,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
false,
|
||||
)
|
||||
.await
|
||||
.object_ids()
|
||||
.collect();
|
||||
assert!(asc_order.len() > 100, "expected >100 metrics, got {}", asc_order.len());
|
||||
let desc_order: Vec<Id> = asc_order.iter().rev().copied().collect();
|
||||
let total = asc_order.len();
|
||||
let limit = 25usize;
|
||||
|
||||
for chunk_start in [0usize, limit, total - limit] {
|
||||
let asc = admin
|
||||
.registry_query_paginated(
|
||||
ObjectType::Metric,
|
||||
"timestamp",
|
||||
true,
|
||||
Some(chunk_start as i32),
|
||||
Some(limit),
|
||||
None,
|
||||
None,
|
||||
false,
|
||||
)
|
||||
.await
|
||||
.object_ids()
|
||||
.collect::<Vec<_>>();
|
||||
assert_eq!(
|
||||
asc,
|
||||
asc_order[chunk_start..chunk_start + limit],
|
||||
"ascending position={chunk_start} limit={limit}",
|
||||
);
|
||||
|
||||
let desc = admin
|
||||
.registry_query_paginated(
|
||||
ObjectType::Metric,
|
||||
"timestamp",
|
||||
false,
|
||||
Some(chunk_start as i32),
|
||||
Some(limit),
|
||||
None,
|
||||
None,
|
||||
false,
|
||||
)
|
||||
.await
|
||||
.object_ids()
|
||||
.collect::<Vec<_>>();
|
||||
assert_eq!(
|
||||
desc,
|
||||
desc_order[chunk_start..chunk_start + limit],
|
||||
"descending position={chunk_start} limit={limit}",
|
||||
);
|
||||
}
|
||||
|
||||
for anchor_idx in [limit - 1, total - limit - 1] {
|
||||
let asc = admin
|
||||
.registry_query_paginated(
|
||||
ObjectType::Metric,
|
||||
"timestamp",
|
||||
true,
|
||||
None,
|
||||
Some(limit),
|
||||
Some(asc_order[anchor_idx]),
|
||||
Some(1),
|
||||
false,
|
||||
)
|
||||
.await
|
||||
.object_ids()
|
||||
.collect::<Vec<_>>();
|
||||
let asc_size = std::cmp::min(limit, total - anchor_idx - 1);
|
||||
assert_eq!(
|
||||
asc,
|
||||
asc_order[anchor_idx + 1..anchor_idx + 1 + asc_size],
|
||||
"ascending anchor={} offset=1 limit={limit}",
|
||||
asc_order[anchor_idx],
|
||||
);
|
||||
|
||||
let desc = admin
|
||||
.registry_query_paginated(
|
||||
ObjectType::Metric,
|
||||
"timestamp",
|
||||
false,
|
||||
None,
|
||||
Some(limit),
|
||||
Some(desc_order[anchor_idx]),
|
||||
Some(1),
|
||||
false,
|
||||
)
|
||||
.await
|
||||
.object_ids()
|
||||
.collect::<Vec<_>>();
|
||||
let desc_size = std::cmp::min(limit, total - anchor_idx - 1);
|
||||
assert_eq!(
|
||||
desc,
|
||||
desc_order[anchor_idx + 1..anchor_idx + 1 + desc_size],
|
||||
"descending anchor={} offset=1 limit={limit}",
|
||||
desc_order[anchor_idx],
|
||||
);
|
||||
}
|
||||
|
||||
// Purge metrics and make sure they are gone
|
||||
test.server
|
||||
.metrics_store()
|
||||
|
||||
Reference in New Issue
Block a user