-
Notifications
You must be signed in to change notification settings - Fork 25.2k
[ML] Avoid 5s wait in AbstractNativeProcessTests #74916
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
Conversation
Pinging @elastic/ml-core (Team:ML) |
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
try (AbstractNativeProcess process = new TestNativeProcess()) { | ||
process.start(executorService); | ||
} finally { | ||
mockNativeProcessLoggingStreamEnds.countDown(); | ||
// Not detecting a crash is confirmed in terminateExecutorService() | ||
} |
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.
I think this could be made even better by nesting the finally
so that we count down before close whether the test passes or fails.
try (AbstractNativeProcess process = new TestNativeProcess()) {
try {
process.start(executorService);
} finally {
mockNativeProcessLoggingStreamEnds.countDown();
// Not detecting a crash is confirmed in terminateExecutorService()
}
}
(And obviously the same pattern for all the other places too.)
Or to avoid nested try
blocks it could be done like we're already doing it in testStart_DoNotDetectCrashWhenProcessIsBeingKilled
:
AbstractNativeProcess process = new TestNativeProcess()) {
try {
process.start(executorService);
} finally {
mockNativeProcessLoggingStreamEnds.countDown();
// Not detecting a crash is confirmed in terminateExecutorService()
process.close();
}
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.
Yes if the test fails or throws before mockNativeProcessLoggingStreamEnds.countDown();
the 5s wait will be hit again. I've optimised for the common case and the fix was pleasingly simple so I didn't go any further.
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.
If you can't be bothered then let me push a change while the PR is open, as at least that will save the effort of two PRs and two backports.
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.
I pushed the nested try
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.
Thanks ❤️
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
Calling close() before counting down the latch was causing a 5 second wait and timeout in the tests
💚 Backport successful
|
Calling close() before counting down the latch was causing a 5 second wait and timeout in the tests Co-authored-by: David Kyle <[email protected]>
Running the unit tests I've noticed
AbstractNativeProcessTests
often takes a long time to complete, individual methods either complete very quickly or take a little over 5 seconds suggesting something is timing out.Indeed the 5 second wait is in the
close()
methodelasticsearch/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/process/AbstractNativeProcess.java
Line 195 in 68817d7
When used in a try-with-resource block
close()
is called beforemockNativeProcessLoggingStreamEnds.countDown()
so the call to wait for the log tail future to finish always times out as it is waiting on themockNativeProcessLoggingStreamEnds
latch to countdown.Closes #37339