chaizy111 opened a new issue, #11540:
URL: https://github.com/apache/rocketmq/issues/11540
### Before Creating the Enhancement Request
- [x] I have confirmed that this should be classified as an enhancement
rather than a bug/feature.
### Summary
Improve the regression protection provided by CountDownLatch2Test.
The current testConstructorError method checks the exception message
inside a catch block, but does not fail if the constructor returns
normally. Therefore, the test can pass even if negative counts stop
being rejected.
### Motivation
The current CountDownLatch2Test.testConstructorError() checks the exception
message inside a catch block, but does not fail if the constructor returns
normally. Therefore, the test would still pass if negative counts were
accidentally accepted in a future change.
The existing tests also do not explicitly verify zero-count initialization,
zero and negative timeouts, or resetting a latch after its count has reached
zero.
Strengthening these tests would improve regression detection and document
the expected boundary behavior. This proposal addresses test quality; it does
not report a defect in the current production implementation.
### Describe the Solution You'd Like
Limit the change to:
common/src/test/java/org/apache/rocketmq/common/CountDownLatch2Test.java
1. Add an explicit fail() assertion after constructing a latch with a
negative count, so testConstructorError() fails if IllegalArgumentException is
not thrown. Preserve the existing exception-message assertion.
2. Add focused tests for:
- A latch initialized with zero being immediately released.
- await() returning false for a zero timeout while the count is positive.
- await() returning false for a negative timeout while the count is
positive.
- Resetting a fully released latch to its initial count and successfully
using it again.
No production code changes or new dependencies are proposed.
Validation will include running the test class and temporarily removing the
constructor's negative-count check to confirm that the improved test detects
the regression.
### Describe Alternatives You've Considered
Using JUnit assertThrows() would also ensure that the constructor rejects
negative counts and would allow checking the exception message. Adding fail()
is proposed as a minimal change that preserves the existing try-catch structure.
Using @Test(expected = IllegalArgumentException.class) would verify the
exception type, but would not directly preserve the existing exception-message
assertion.
Keeping the current test unchanged would leave the false-positive path
unaddressed.
### Additional Context
This is a small test-quality improvement related to #10373.
I would like to work on this change.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]