-
Notifications
You must be signed in to change notification settings - Fork 292
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ensure queue timer is started for RunnableFuture types
- Loading branch information
1 parent
e20dfff
commit e893948
Showing
3 changed files
with
82 additions
and
4 deletions.
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
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
62 changes: 62 additions & 0 deletions
62
dd-java-agent/instrumentation/java-concurrent/src/test/groovy/QueueTimingForkedTest.groovy
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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import datadog.trace.agent.test.AgentTestRunner | ||
import datadog.trace.agent.test.TestProfilingContextIntegration | ||
import datadog.trace.bootstrap.instrumentation.jfr.InstrumentationBasedProfiling | ||
|
||
import java.util.concurrent.ExecutorService | ||
import java.util.concurrent.Executors | ||
import java.util.concurrent.ForkJoinPool | ||
|
||
import static datadog.trace.agent.test.utils.TraceUtils.runUnderTrace | ||
|
||
class QueueTimingForkedTest extends AgentTestRunner { | ||
|
||
@Override | ||
protected void configurePreAgent() { | ||
// required for enabling the unwrapping instrumentation to get the relevant non-carrier class names | ||
injectSysConfig("dd.profiling.enabled", "true") | ||
injectSysConfig("dd.profiling.experimental.queueing.time.enabled", "true") | ||
InstrumentationBasedProfiling.enableInstrumentationBasedProfiling() | ||
super.configurePreAgent() | ||
} | ||
|
||
def "test queue timing with submit #executor"() { | ||
|
||
when: | ||
runUnderTrace("parent", { | ||
executor.submit(new TestRunnable()).get() | ||
}) | ||
|
||
then: | ||
verify(executor) | ||
|
||
cleanup: | ||
executor.shutdown() | ||
TEST_PROFILING_CONTEXT_INTEGRATION.closedTimings.clear() | ||
|
||
where: | ||
executor << [Executors.newSingleThreadExecutor(), new ForkJoinPool(1)] | ||
} | ||
|
||
void verify(ExecutorService executorService) { | ||
assert TEST_PROFILING_CONTEXT_INTEGRATION.isBalanced() | ||
assert !TEST_PROFILING_CONTEXT_INTEGRATION.closedTimings.isEmpty() | ||
int numAsserts = 0 | ||
while (!TEST_PROFILING_CONTEXT_INTEGRATION.closedTimings.isEmpty()) { | ||
def timing = TEST_PROFILING_CONTEXT_INTEGRATION.closedTimings.takeFirst() as TestProfilingContextIntegration.TestQueueTiming | ||
if (!(timing.task as Class).simpleName.isEmpty()) { | ||
assert timing != null | ||
assert timing.task == TestRunnable | ||
assert timing.scheduler != null | ||
assert timing.origin == Thread.currentThread() | ||
numAsserts++ | ||
} | ||
} | ||
assert numAsserts > 0 | ||
} | ||
|
||
|
||
class TestRunnable implements Runnable { | ||
@Override | ||
void run() {} | ||
} | ||
} |