-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[fix][test] Fix ManagedCursorTest.testForceCursorRecovery #23518
Conversation
@ZhaoGuorui666 Please add the following content to your PR description and select a checkbox:
|
Could you verify https://github.com/apache/pulsar/pull/23518/files#diff-42dd67f8328871b3f0d30446ed1a4f1856807860c5226a9ec6c4d3a9f8813428R4882? Hrere should append a |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #23518 +/- ##
============================================
+ Coverage 73.57% 74.31% +0.74%
- Complexity 32624 34906 +2282
============================================
Files 1877 1943 +66
Lines 139502 147001 +7499
Branches 15299 16196 +897
============================================
+ Hits 102638 109247 +6609
- Misses 28908 29306 +398
- Partials 7956 8448 +492
Flags with carried forward coverage won't be shown. Click here to find out more. |
In this test, we are using
It seems that the test results were affected by multiple callback calls. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a comment.
@nodece Thank you for your prompt and suggestion. It has been revised. |
From the log of failed test, we can see So We don't need to add public void asyncOpenLedger(final long lId, final DigestType digestType, final byte[] passwd,
final OpenCallback cb, final Object ctx) {
if (ledgerErrors.containsKey(lId)) {
cb.openComplete(ledgerErrors.get(lId), null, ctx);
} else {
super.asyncOpenLedger(lId, digestType, passwd, cb, ctx);
}
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
managed-ledger/src/test/java/org/apache/bookkeeper/mledger/impl/ManagedCursorTest.java
Outdated
Show resolved
Hide resolved
managed-ledger/src/test/java/org/apache/bookkeeper/mledger/impl/ManagedCursorTest.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, good work @ZhaoGuorui666. Thanks for putting effort in fixing flaky tests.
(cherry picked from commit d2d05c2)
Fixes #23417
Motivation
Ideally, recoverFromLedger should only call operationComplete upon successful recovery and operationFailed upon failure. However, in the actual implementation, both methods may be called due to the following reasons:
Concurrent Execution: If recoverFromLedger is executed in different threads, it may simultaneously meet both success and failure conditions, leading to both callbacks being triggered.
After adding logs, we may see both:
Modifications
Use an atomic variable. Use an AtomicBoolean in the callback to mark whether the callback method has already been called, preventing duplicate calls.
Documentation
doc
doc-required
doc-not-needed
doc-complete