Skip to content

tests: priority-aging end-to-end checks for queue_storage runtime claim#249

Merged
hardbyte merged 1 commit into
mainfrom
fix/priority-aging-test
May 10, 2026
Merged

tests: priority-aging end-to-end checks for queue_storage runtime claim#249
hardbyte merged 1 commit into
mainfrom
fix/priority-aging-test

Conversation

@hardbyte
Copy link
Copy Markdown
Owner

@hardbyte hardbyte commented May 9, 2026

Summary

Two unit tests pinning the priority-aging mechanism in `QueueStorage::claim_runtime_batch_with_aging`. Motivated by the 2026-05-09 cross-system sweep's `starvation_awa_60min` cell reporting `aged_completion_rate=0` across a 60 minute soak — confirms the mechanism is in fact working, so the gap is on the bench side.

  • `test_priority_aging_lifts_effective_priority_and_records_original`: enqueue a priority-4 job, sleep past two aging windows (250 ms with a 100 ms interval), claim, assert effective priority < 4 and `metadata._awa_original_priority = 4`.
  • `test_priority_aging_off_does_not_stamp_original`: same enqueue, 1 hour aging interval; assert priority unchanged and metadata absent. Guards `into_job_row`'s `priority < lane_priority` branch.

What this isn't fixing

The bench cell `aged_completion_rate=0` is real but downstream of these tests. `JOB_WORK_MS=1` with `rate=300` doesn't accumulate enough wait time on the priority-4 lane to hit the bench's 60 s default aging interval. Two options:

  1. Lower `PRIORITY_AGING_MS` in the bench cell (already env-configurable).
  2. Raise producer rate above worker capacity for the priority-1 lane so priority-4 jobs back up.

Tracked as a follow-up; does not need to land in this PR.

Test plan

  • `SQLX_OFFLINE=true cargo build -p awa --tests`
  • `SQLX_OFFLINE=true cargo clippy -p awa --tests -- -D warnings`
  • `cargo fmt --all`
  • `cargo test -p awa --test queue_storage_runtime_test test_priority_aging` — both pass against pg18

Summary by CodeRabbit

  • Tests
    • Added tests validating priority-aging functionality in job queue operations, including verification of priority adjustments and metadata handling when aging is enabled and disabled.

Review Change Stack

Two tests covering both branches of the aging guard in
ReadyJobLeaseRow::into_job_row:

- test_priority_aging_lifts_effective_priority_and_records_original:
  enqueues a priority-4 job, waits 250 ms, claims with a 100 ms aging
  interval, asserts the claimed job's effective priority is < 4 and
  metadata._awa_original_priority records the lane priority of 4.

- test_priority_aging_off_does_not_stamp_original: same enqueue but
  with a 1 hour aging interval; asserts effective priority equals lane
  priority and metadata._awa_original_priority is absent. Pins the
  no-aging branch so a future refactor cannot accidentally always-stamp
  the metadata.

Motivated by the 2026-05-09 sweep's starvation_awa_60min cell reporting
aged_completion_rate=0 across a 60 minute soak. The mechanism works at
the SQL level (these tests pass at a 100 ms interval); the bench-side
gap is that JOB_WORK_MS=1 with rate=300 doesn't create the queue
starvation needed to reach the 60 s default aging interval. Tracked as
a follow-up to lower the bench cell's aging interval or raise
producer rate above worker capacity for the high-priority lane.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 9, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ab2c5ac0-4c87-4da5-a137-f25a3f51cd86

📥 Commits

Reviewing files that changed from the base of the PR and between 4ec023f and f4d33ac.

📒 Files selected for processing (1)
  • awa/tests/queue_storage_runtime_test.rs

📝 Walkthrough

Walkthrough

This PR adds two Tokio integration tests to verify priority-aging behavior in the queue storage runtime. The tests exercise claim operations with aging both enabled and disabled, validating that effective priority is adjusted and metadata is stamped appropriately when aging triggers.

Changes

Priority-Aging Tests

Layer / File(s) Summary
Priority-Aging Test Cases
awa/tests/queue_storage_runtime_test.rs
test_priority_aging_lifts_effective_priority_and_records_original enqueues a priority-4 job, waits past aging windows, and claims with aging enabled to verify effective priority is reduced and _awa_original_priority is stamped. test_priority_aging_off_does_not_stamp_original verifies that disabling aging keeps priority unchanged and omits original priority metadata.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • hardbyte/awa#213: Refactors claimer heartbeat/lease-refresh behavior in the claim runtime path that these tests exercise.
  • hardbyte/awa#222: Modifies claim transaction behavior in claim_runtime_batch_with_aging_physical, which directly affects how priority-aging logic processes claimed rows.

Poem

🐰 A rabbit hops through aging queues so fine,
With priorities that shift and gracefully align,
Two tests now hop to verify the way,
That jobs grow younger with each passing day! 🥕

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: addition of end-to-end tests for priority-aging behavior in queue_storage runtime claim functionality.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/priority-aging-test

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant