Repository navigation
Conversation
Reviewer's GuideImplementationMove semaphore release into a per-message task wrapper and await message processing within that task, centralizing semaphore ownership at the task boundary.
TestsAdd tests checking that the per-message wrapper releases the semaphore after invalid-message and successful processing paths.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 2 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="tests/listener_tests/test_listener_semaphore.py" line_range="67" />
<code_context>
+ record = create_consumer_record(invalid_json)
+
+ # Use the exact method name from listener_2.py
+ await listener._handle_single_consume_message(record)
+
+ # Assert it was released (if we try to release a fully bounded semaphore, it raises ValueError)
</code_context>
<issue_to_address>
**Processing errors go untested**
When message processing raises an exception after JSON decoding, `invalid_json` raises `JSONDecodeError`, which `_consume_message` catches and returns from, so `_handle_single_consume_message` completes normally and the semaphore assertion passes even if cleanup after a processing exception is broken; regressions in release-on-exception go unnoticed.
Use valid JSON and make the inventory or advisor processor raise an exception, then assert that the semaphore was released.
</issue_to_address>
### Comment 2
<location path="tests/listener_tests/test_listener_semaphore.py" line_range="94" />
<code_context>
+ await listener._handle_single_consume_message(record)
+
+ # Assert it was released (if we try to release a fully bounded semaphore, it raises ValueError)
+ with pytest.raises(ValueError):
+ listener.max_messages_semaphore.release()
+
</code_context>
<issue_to_address>
**Early release still passes**
When the handler releases the semaphore slot before message processing completes, `test_semaphore_released_on_success` (lines 91-97) checks the semaphore only after the handler finishes; releasing the slot before awaiting processing still leaves it full at line 94 and lets the processor assertion pass, so the test accepts premature release.
Block the mocked processor on an event, assert the slot remains acquired while processing is blocked, then unblock it and verify the slot is released.
</issue_to_address>| record = create_consumer_record(invalid_json) | ||
|
|
||
| # Use the exact method name from listener_2.py | ||
| await listener._handle_single_consume_message(record) |
There was a problem hiding this comment.
🟡 Medium · Processing errors go untested
When message processing raises an exception after JSON decoding, invalid_json raises JSONDecodeError, which _consume_message catches and returns from, so _handle_single_consume_message completes normally and the semaphore assertion passes even if cleanup after a processing exception is broken; regressions in release-on-exception go unnoticed.
Use valid JSON and make the inventory or advisor processor raise an exception, then assert that the semaphore was released.
Prompt for AI agents
In `tests/listener_tests/test_listener_semaphore.py` at line 67:
**Processing errors go untested**
When message processing raises an exception after JSON decoding, `invalid_json` raises `JSONDecodeError`, which `_consume_message` catches and returns from, so `_handle_single_consume_message` completes normally and the semaphore assertion passes even if cleanup after a processing exception is broken; regressions in release-on-exception go unnoticed.
Use valid JSON and make the inventory or advisor processor raise an exception, then assert that the semaphore was released.| await listener._handle_single_consume_message(record) | ||
|
|
||
| # Assert it was released back to its maximum bound | ||
| with pytest.raises(ValueError): |
There was a problem hiding this comment.
🟡 Medium · Early release still passes
When the handler releases the semaphore slot before message processing completes, test_semaphore_released_on_success (lines 91-97) checks the semaphore only after the handler finishes; releasing the slot before awaiting processing still leaves it full at line 94 and lets the processor assertion pass, so the test accepts premature release.
Block the mocked processor on an event, assert the slot remains acquired while processing is blocked, then unblock it and verify the slot is released.
Prompt for AI agents
In `tests/listener_tests/test_listener_semaphore.py` at line 94:
**Early release still passes**
When the handler releases the semaphore slot before message processing completes, `test_semaphore_released_on_success` (lines 91-97) checks the semaphore only after the handler finishes; releasing the slot before awaiting processing still leaves it full at line 94 and lets the processor assertion pass, so the test accepts premature release.
Block the mocked processor on an event, assert the slot remains acquired while processing is blocked, then unblock it and verify the slot is released.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #2763 +/- ##
==========================================
+ Coverage 64.53% 69.84% +5.31%
==========================================
Files 55 61 +6
Lines 6469 7761 +1292
==========================================
+ Hits 4175 5421 +1246
- Misses 2294 2340 +46 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Messages semaphore wrapped into handle single consume message so we have better control over semaphore acquires and releases instead of relying on the component that does not know about the semaphore resultion into a single semaphore acquire and release. RHINENG-33634
ff08200 to
efbffd0
Compare
Messages semaphore wrapped into handle single consume message so we have better control over semaphore acquires and releases instead of relying on the component that does not know about the semaphore resultion into a single semaphore acquire and release. RHINENG-33634
Secure Coding Practices Checklist GitHub Link
Secure Coding Checklist
Summary by Sourcery
Fix message consumption so semaphore capacity is reliably restored after every message.
Bug Fixes:
Enhancements:
Tests: