-
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
Use a dedicated test executor in MockTransportService #112748
Merged
elasticsearchmachine
merged 3 commits into
elastic:main
from
ywangd:use-test-executor-in-mock-transport
Sep 12, 2024
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,8 @@ | |
import org.elasticsearch.common.util.CollectionUtils; | ||
import org.elasticsearch.common.util.MockPageCacheRecycler; | ||
import org.elasticsearch.common.util.concurrent.AbstractRunnable; | ||
import org.elasticsearch.common.util.concurrent.EsExecutors; | ||
import org.elasticsearch.common.util.concurrent.EsThreadPoolExecutor; | ||
import org.elasticsearch.common.util.concurrent.RunOnce; | ||
import org.elasticsearch.core.AbstractRefCounted; | ||
import org.elasticsearch.core.IOUtils; | ||
|
@@ -206,6 +208,7 @@ public static MockTransportService getInstance(String nodeName) { | |
} | ||
|
||
private final Transport original; | ||
private final EsThreadPoolExecutor testExecutor; | ||
|
||
/** | ||
* Build the service. | ||
|
@@ -302,6 +305,16 @@ private MockTransportService( | |
Tracer.NOOP | ||
); | ||
this.original = transport.getDelegate(); | ||
this.testExecutor = EsExecutors.newScaling( | ||
"mock-transport", | ||
0, | ||
4, | ||
30, | ||
TimeUnit.SECONDS, | ||
false, | ||
EsExecutors.daemonThreadFactory("mock-transport"), | ||
threadPool.getThreadContext() | ||
); | ||
} | ||
|
||
private static TransportAddress[] extractTransportAddresses(TransportService transportService) { | ||
|
@@ -617,7 +630,7 @@ protected void doRun() throws IOException { | |
delay | ||
) | ||
); | ||
threadPool.schedule(runnable, delay, threadPool.generic()); | ||
threadPool.schedule(runnable, delay, testExecutor); | ||
} | ||
} | ||
} | ||
|
@@ -795,6 +808,8 @@ protected void doClose() throws IOException { | |
} | ||
} catch (InterruptedException e) { | ||
throw new IllegalStateException(e); | ||
} finally { | ||
ThreadPool.terminate(testExecutor, 10, TimeUnit.SECONDS); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we have an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep see 63a4614 |
||
} | ||
} | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Could we set
rejectAfterShutdown
totrue
please?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 pondered on this and decided to use
false
to align with how the generic executor is defined. I also think it might be better to let the "real" executors to decide whether task should be rejected, i.e. if the task has reached here, it is not rejected and we should just queue it up. That said, I am OK withtrue
as well since it was my initial preference for better predictability. See 63a4614There 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.
Sure but that's not what
false
does, it just silently drops any work submitted after shutdown.My thinking here is twofold: firstly, we are terminating this
ExecutorService
at the end of the test, there should be no more tasks submitted by that point anyway. Secondly, IMO the silent-drop behaviour ofgeneric
after shutdown is a bug, even if it is unfortunately one we cannot easily address without changing lots of other things, but we can at least avoid relying on that same behaviour in specific situations like this one.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.
TIL. Thanks!