Liking cljdoc? Tell your friends :D

Implementation Checklist: Issue 12

Phase 1: Code Changes (5 edits)

[ ] 1. Add :in-progress Counter to initial-stats

  • File: src/clj_commons/durable_queue.clj
  • Line: 407-410
  • Change: Add :in-progress (AtomicLong. 0) to the map
  • Verification: Check that the new key is present in returned map

[ ] 2. Update immediate-stats to Read Direct Counter

  • File: src/clj_commons/durable_queue.clj
  • Lines: 412-419
  • Changes:
    • Remove cnt variable (.size q call)
    • Remove destructuring of :in-progress from parameters (it will now be used)
    • Change :in-progress value from formula to (.get ^AtomicLong in-progress)
  • Verification: Function now has fewer operations and no race window

[ ] 3. Update mark-complete! to Decrement in-progress

  • File: src/clj_commons/durable_queue.clj
  • Lines: 649-653
  • Changes:
    • Add destructuring of :in-progress from stats
    • Add (.decrementAndGet in-progress-counter) after incrementing completed
  • Verification: in-progress decrements when task completes

[ ] 4. Update mark-retry! to Decrement in-progress

  • File: src/clj_commons/durable_queue.clj
  • Lines: 643-647
  • Changes:
    • Add destructuring of :in-progress from stats
    • Add (.decrementAndGet in-progress-counter) after incrementing retried
  • Verification: in-progress decrements when task is retried

[ ] 5. Update take! to Increment in-progress

  • File: src/clj_commons/durable_queue.clj
  • Lines: 668-695
  • Changes:
    • After (status! t :in-progress) add:
      (populate-stats! q-name)
      (let [^AtomicLong counter (get-in @queue-name->stats [q-name :in-progress])]
        (.incrementAndGet counter))
      
  • Verification: in-progress increments when item is taken from queue

Phase 2: Testing (Add Tests)

[ ] 6. Write Unit Tests for in-progress Counter

  • File: test/clj_commons/durable_queue_test.clj
  • Tests to Add:
    • test-in-progress-starts-at-zero: After creating queue, in-progress should be 0
    • test-in-progress-increments-on-take: After take!, in-progress should be 1
    • test-in-progress-decrements-on-complete: After mark-complete!, in-progress should be 0
    • test-in-progress-decrements-on-retry: After mark-retry!, in-progress should be 0
    • test-in-progress-multiple-items: After multiple take!s, in-progress should equal number taken
    • test-in-progress-never-negative: Verify in-progress >= 0 in all scenarios
  • Coverage: Cover happy path and edge cases

[ ] 7. Write Concurrency Test

  • File: test/clj_commons/durable_queue_test.clj
  • Test: test-in-progress-thread-safe
  • Scenario:
    • Create queue with 100 items
    • Spawn 10 threads that call take! in a loop
    • Spawn 10 threads that call mark-complete! in a loop
    • Collect stats every 10ms
    • Verify:
      • in-progress never goes negative
      • in-progress values are always consistent
      • Final in-progress matches expected value
  • Duration: Run for at least 2 seconds

Phase 3: Verification

[ ] 8. Run Existing Test Suite

  • Command: clj -M:test or bb test
  • Expected: All existing tests pass
  • If Failed: Debug and ensure no regressions introduced

[ ] 9. Run New Tests

  • Command: clj -M:test durable_queue_test/test-in-progress* (or equivalent)
  • Expected: All new tests pass
  • If Failed: Verify implementation matches the plan

[ ] 10. Manual Smoke Test

  • Create a simple script that:
    • Creates a queue manager
    • Enqueues 10 items
    • Takes 5 items
    • Marks 3 as complete, 2 as retry
    • Checks stats at each step
    • Prints results for visual inspection

Phase 4: Documentation

[ ] 11. Update Code Comments

  • Explain why in-progress is tracked directly (race condition avoidance)
  • Document the increment/decrement points

[ ] 12. Update CHANGELOG

  • Note: Fixed race condition in in-progress statistics
  • Add: Issue 12 implementation details if relevant

[ ] 13. Create Implementation Notes

  • Document any interesting findings or gotchas
  • Note performance characteristics before/after

Troubleshooting Guide

Problem: Tests fail after change 1

Check: Does initial-stats create all 4 counters? Fix: Ensure :in-progress (AtomicLong. 0) is in the returned map

Problem: Tests fail after change 2

Check: Does immediate-stats receive :in-progress parameter? Fix: Ensure destructuring includes in-progress in function signature

Problem: Tests fail after change 3-5

Check: Are stats being populated before accessing? Fix: Ensure (populate-stats! q-name) is called before accessing counter

Problem: in-progress goes negative

Check: Are all decrement points implemented (mark-complete! and mark-retry!)? Fix: Verify mark-retry! decrements the counter

Problem: in-progress doesn't increment

Check: Is take! incrementing the counter? Fix: Verify increment code is in the success path (inside the if-let)

Problem: Tests hang or timeout

Check: Is there a deadlock in stats access? Fix: Verify no circular locking or long-held locks


Sign-Off

After completing all items:

  • [ ] All code changes implemented
  • [ ] All tests passing
  • [ ] No regressions in existing functionality
  • [ ] Documentation updated
  • [ ] Ready for code review

Estimated Time: 2-4 hours for experienced developer Risk Level: Low (isolated to stats tracking, no behavior changes) Rollback Plan: Revert 5 edits; existing behavior restored


Code Review Checklist

Reviewer should verify:

  • [ ] 5 code changes match the plan exactly
  • [ ] No unrelated changes introduced
  • [ ] All test cases cover the race condition
  • [ ] Performance is not negatively impacted
  • [ ] Edge cases handled (empty queue, single item, etc.)
  • [ ] Backward compatibility maintained
  • [ ] Documentation is clear and complete

Can you improve this documentation?Edit on GitHub

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
←Move to previous article
→Move to next article
Ctrl+/Jump to the search field
× close