-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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
Add utility for asserting listeners are completed #109325
Add utility for asserting listeners are completed #109325
Conversation
server/src/main/java/org/elasticsearch/action/ActionListenerImplementations.java
Outdated
Show resolved
Hide resolved
server/src/main/java/org/elasticsearch/action/ActionListenerImplementations.java
Outdated
Show resolved
Hide resolved
server/src/test/java/org/elasticsearch/action/ActionListenerTests.java
Outdated
Show resolved
Hide resolved
3e9ed60
to
78b05fc
Compare
78b05fc
to
984e2fd
Compare
server/src/main/java/org/elasticsearch/action/ActionListenerImplementations.java
Outdated
Show resolved
Hide resolved
server/src/main/java/org/elasticsearch/action/ActionListener.java
Outdated
Show resolved
Hide resolved
Pinging @elastic/es-distributed (Team:Distributed) |
server/src/main/java/org/elasticsearch/action/ActionListenerImplementations.java
Outdated
Show resolved
Hide resolved
server/src/main/java/org/elasticsearch/action/ActionListenerImplementations.java
Outdated
Show resolved
Hide resolved
server/src/test/java/org/elasticsearch/action/ActionListenerTests.java
Outdated
Show resolved
Hide resolved
server/src/test/java/org/elasticsearch/action/ActionListenerTests.java
Outdated
Show resolved
Hide resolved
…plementations.java Co-authored-by: Ievgen Degtiarenko <ievgen.degtiarenko@gmail.com>
server/src/test/java/org/elasticsearch/action/ActionListenerTests.java
Outdated
Show resolved
Hide resolved
server/src/test/java/org/elasticsearch/action/ActionListenerTests.java
Outdated
Show resolved
Hide resolved
server/src/test/java/org/elasticsearch/action/ActionListenerTests.java
Outdated
Show resolved
Hide resolved
server/src/main/java/org/elasticsearch/action/ActionListener.java
Outdated
Show resolved
Hide resolved
server/src/test/java/org/elasticsearch/action/ActionListenerTests.java
Outdated
Show resolved
Hide resolved
server/src/test/java/org/elasticsearch/transport/LeakTrackerTests.java
Outdated
Show resolved
Hide resolved
/** | ||
* Encapsulates the lifecycle for a particular type of tracked object | ||
*/ | ||
public interface TrackedObjectTestCase { |
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.
Probably more elaborate than I would have liked, but the lifecycles of the different wrappers seemed different enough to make it worthwhile.
server/src/test/java/org/elasticsearch/transport/LeakTrackerTests.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.
Looks good, left some more comments. I suggest breaking out the leak-tracker tests into a separate PR too.
server/src/main/java/org/elasticsearch/action/ActionListener.java
Outdated
Show resolved
Hide resolved
server/src/test/java/org/elasticsearch/transport/LeakTrackerTests.java
Outdated
Show resolved
Hide resolved
server/src/test/java/org/elasticsearch/transport/LeakTrackerTests.java
Outdated
Show resolved
Hide resolved
server/src/test/java/org/elasticsearch/transport/LeakTrackerTests.java
Outdated
Show resolved
Hide resolved
server/src/test/java/org/elasticsearch/transport/LeakTrackerTests.java
Outdated
Show resolved
Hide resolved
*/ | ||
protected static void assertLeakDetected(String expectedPattern) { | ||
synchronized (loggedLeaks) { | ||
assertTrue(loggedLeaks.removeIf(leakText -> Pattern.matches(expectedPattern, leakText))); |
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.
Neat.
Comments are addressed now, I've applied the suggested changes and stored the LeakTracker locally ready to open a separate PR after this is merged (it depends on |
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.
Looks good, just a couple of nits on the tests.
server/src/test/java/org/elasticsearch/action/ActionListenerTests.java
Outdated
Show resolved
Hide resolved
server/src/test/java/org/elasticsearch/action/ActionListenerTests.java
Outdated
Show resolved
Hide resolved
…sts.java Co-authored-by: David Turner <david.turner@elastic.co>
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
Closes #108123
Because we can only be sure that the listener was not called when it finally gets GC'd, it may not fail tests that cause the situation to arise, or even log during them, as the GC may happen some time after they're completed, or in a separate VM. This is somewhat mitigated by the fact that
LeakTracker
will include the test name in thecontextHint
.Perhaps it would be handy to be able to also trigger these checks in
@AfterEach
(i.e. potentially before GC) so for in-process tests we could fail the test in which the assertion was violated? I have an idea of how this might work