-
Notifications
You must be signed in to change notification settings - Fork 303
more executor tests #2002
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
Merged
Merged
more executor tests #2002
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e04c29f
test grpc with both direct and cached thread pool executors
richardstartin 1432962
remove guava wrapping executors from permitted list
richardstartin c56dca6
netty concurrent tests
richardstartin 8a3869a
test propagation from within netty eventloop
richardstartin 79542fb
instrument netty rejected execution handlers
richardstartin 98c8f22
disable netty UnorderedThreadPoolEventExecutor cross-context test (oc…
richardstartin 219b5e7
disable testing of UnorderedThreadPoolEventExecutor
richardstartin 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 hidden or 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
This file contains hidden or 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
This file contains hidden or 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
141 changes: 141 additions & 0 deletions
141
dd-java-agent/instrumentation/java-concurrent/src/test/groovy/CrossedContextTest.groovy
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,141 @@ | ||
import datadog.trace.agent.test.AgentTestRunner | ||
import datadog.trace.core.DDSpan | ||
import io.netty.channel.DefaultEventLoopGroup | ||
import io.netty.channel.ThreadPerChannelEventLoop | ||
import io.netty.channel.nio.NioEventLoopGroup | ||
import io.netty.channel.oio.OioEventLoopGroup | ||
import io.netty.util.concurrent.DefaultEventExecutor | ||
import org.apache.tomcat.util.threads.TaskQueue | ||
import spock.lang.Shared | ||
|
||
import java.util.concurrent.ExecutorService | ||
import java.util.concurrent.Executors | ||
import java.util.concurrent.ForkJoinPool | ||
import java.util.concurrent.ThreadFactory | ||
import java.util.concurrent.TimeUnit | ||
import java.util.concurrent.atomic.AtomicInteger | ||
|
||
import static datadog.trace.agent.test.utils.TraceUtils.runUnderTrace | ||
|
||
class CrossedContextTest extends AgentTestRunner { | ||
|
||
@Shared | ||
def executeRunnable = { e, c -> e.execute((Runnable) c) } | ||
@Shared | ||
def submitRunnable = { e, c -> e.submit((Runnable) c) } | ||
|
||
// this pool is not what's being tested | ||
@Shared | ||
ExecutorService pool = Executors.newFixedThreadPool(40, new ThreadFactory() { | ||
AtomicInteger i = new AtomicInteger() | ||
|
||
@Override | ||
Thread newThread(Runnable r) { | ||
Thread t = new Thread(r) | ||
t.setName("parent-" + i.getAndIncrement()) | ||
return t | ||
} | ||
}) | ||
|
||
def cleanupSpec() { | ||
pool.shutdownNow() | ||
} | ||
|
||
def "concurrent #action are traced with correct lineage in #executor"() { | ||
when: | ||
def sut = executor | ||
def fn = function | ||
int taskCount = 200 | ||
for (int i = 0; i < taskCount; ++i) { | ||
pool.execute({ | ||
String threadName = Thread.currentThread().getName() | ||
runUnderTrace(threadName) { | ||
fn(sut, new Descendant(threadName)) | ||
} | ||
}) | ||
} | ||
|
||
TEST_WRITER.waitForTraces(taskCount) | ||
then: | ||
for (List<DDSpan> trace : TEST_WRITER) { | ||
assert trace.size() == 2 | ||
DDSpan parent = trace.find({ it.isRootSpan() }) | ||
assert null != parent | ||
DDSpan child = trace.find({ it.getParentId() == parent.getSpanId() }) | ||
assert null != child | ||
assert child.getOperationName().toString().startsWith(parent.getOperationName().toString()) | ||
} | ||
|
||
cleanup: | ||
executor.shutdownNow() | ||
|
||
where: | ||
executor | action | function | ||
new ForkJoinPool() | "submission" | submitRunnable | ||
new ForkJoinPool(10) | "submission" | submitRunnable | ||
Executors.newSingleThreadExecutor() | "submission" | submitRunnable | ||
Executors.newSingleThreadScheduledExecutor() | "submission" | submitRunnable | ||
Executors.newFixedThreadPool(10) | "submission" | submitRunnable | ||
Executors.newScheduledThreadPool(10) | "submission" | submitRunnable | ||
Executors.newCachedThreadPool() | "submission" | submitRunnable | ||
new DefaultEventLoopGroup(10) | "submission" | submitRunnable | ||
new DefaultEventLoopGroup(1).next() | "submission" | submitRunnable | ||
// TODO - flaky - seems to be relying on PendingTrace flush | ||
// new UnorderedThreadPoolEventExecutor(10) | "submission" | submitRunnable | ||
new NioEventLoopGroup(10) | "submission" | submitRunnable | ||
new DefaultEventExecutor() | "submission" | submitRunnable | ||
new org.apache.tomcat.util.threads.ThreadPoolExecutor(1, 1, 5, TimeUnit.SECONDS, new TaskQueue()) | "submission" | submitRunnable | ||
new ForkJoinPool() | "execution" | executeRunnable | ||
new ForkJoinPool(10) | "execution" | executeRunnable | ||
Executors.newSingleThreadExecutor() | "execution" | executeRunnable | ||
Executors.newSingleThreadScheduledExecutor() | "execution" | executeRunnable | ||
Executors.newFixedThreadPool(10) | "execution" | executeRunnable | ||
Executors.newScheduledThreadPool(10) | "execution" | executeRunnable | ||
Executors.newCachedThreadPool() | "execution" | executeRunnable | ||
new DefaultEventLoopGroup(10) | "execution" | executeRunnable | ||
new DefaultEventLoopGroup(1).next() | "execution" | executeRunnable | ||
// TODO - flaky - seems to be relying on PendingTrace flush | ||
// new UnorderedThreadPoolEventExecutor(10) | "execution" | executeRunnable | ||
new NioEventLoopGroup(10) | "execution" | executeRunnable | ||
new DefaultEventExecutor() | "execution" | executeRunnable | ||
new org.apache.tomcat.util.threads.ThreadPoolExecutor(1, 1, 5, TimeUnit.SECONDS, new TaskQueue()) | "execution" | executeRunnable | ||
} | ||
|
||
def "netty event loop internal executions in #executor are traced with correct lineage" () { | ||
setup: | ||
ExecutorService pool = executor | ||
when: | ||
|
||
int taskCount = 200 | ||
for (int i = 0; i < taskCount; ++i) { | ||
pool.execute({ | ||
String threadName = Thread.currentThread().getName() | ||
runUnderTrace(threadName) { | ||
pool.execute(new Descendant(threadName)) | ||
} | ||
}) | ||
} | ||
|
||
TEST_WRITER.waitForTraces(taskCount) | ||
then: | ||
for (List<DDSpan> trace : TEST_WRITER) { | ||
assert trace.size() == 2 | ||
DDSpan parent = trace.find({ it.isRootSpan() }) | ||
assert null != parent | ||
DDSpan child = trace.find({ it.getParentId() == parent.getSpanId() }) | ||
assert null != child | ||
assert child.getOperationName().toString().startsWith(parent.getOperationName().toString()) | ||
} | ||
|
||
where: | ||
executor << [ | ||
new ThreadPerChannelEventLoop(new OioEventLoopGroup()), | ||
new DefaultEventExecutor(), | ||
new NioEventLoopGroup(10), | ||
new DefaultEventLoopGroup(10) | ||
// flaky | ||
// new UnorderedThreadPoolEventExecutor(10) | ||
] | ||
} | ||
|
||
} |
This file contains hidden or 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
Oops, something went wrong.
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.
The executors here all just wrap other executors