-
Notifications
You must be signed in to change notification settings - Fork 25k
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
Assert that ActionListener.runBefore/runAfter are executed once #93143
Assert that ActionListener.runBefore/runAfter are executed once #93143
Conversation
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
server/src/main/java/org/elasticsearch/action/ActionListener.java
Outdated
Show resolved
Hide resolved
@@ -452,6 +467,14 @@ public void onFailure(Exception e) { | |||
super.onFailure(e); | |||
} | |||
|
|||
private boolean assertNotExecuted() { | |||
if (Assertions.ENABLED) { |
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.
We can't get here if assertions are disabled I think
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.
Right, thanks! e62d927
@@ -454,6 +457,63 @@ public void onFailure(Exception e) { | |||
assertThat(exReference.get(), instanceOf(IllegalStateException.class)); | |||
} | |||
|
|||
public void testRunBeforeThrowsAssertionErrorIfExecutedMoreThanOnce() { | |||
assumeTrue("test only works with assertions enabled", Assertions.ENABLED); |
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.
Huh TIL it's possible to run tests with assertions disabled! I wouldn't be surprised if this didn't work in lots of other ways too tho.
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.
Yep...
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.
Sorry forgot to press the button.
FWIW I think the way ActionListener#wrap
sometimes calls both onResponse
and onFailure
is kinda evil. Useful sometimes, but evil nonetheless.
@elasticmachine run update branch |
Pinging @elastic/es-core-infra (Team:Core/Infra) |
@elasticmachine update branch |
Thanks David
++, something to be aware of |
Alternative approach to elastic#93143, avoiding adding overhead in production.
Alternative approach to #93143, avoiding adding overhead in production.
I've recently encountered a bug (illustrated by a test in this pull request) where a
ActionListener.runAfter
listener got called multiple times because of an unexpected exception was thrown in a wrapped listener.Asserting that the
runAfter
orreleaseAfter
is called only once would have helped a lot to catch the bug. We don't enforce listeners (or delegating listeners) to be called once and some of them are designed on purpose to be called multiple times, yet I think we can expectrunBefore/runAfter
to be used to release resources and as such they should be run once.I remain open to contrary opinions of course.