-
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 b7cf900
Showing
3 changed files
with
78 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
59 changes: 59 additions & 0 deletions
59
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,59 @@ | ||
import datadog.trace.agent.test.AgentTestRunner | ||
import datadog.trace.agent.test.TestProfilingContextIntegration | ||
import datadog.trace.bootstrap.instrumentation.jfr.InstrumentationBasedProfiling | ||
|
||
import java.util.concurrent.Executors | ||
|
||
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"() { | ||
setup: | ||
def executor = Executors.newSingleThreadExecutor() | ||
|
||
when: | ||
runUnderTrace("parent", { | ||
executor.submit(new TestRunnable()).get() | ||
}) | ||
|
||
then: | ||
verify() | ||
|
||
cleanup: | ||
executor.shutdown() | ||
TEST_PROFILING_CONTEXT_INTEGRATION.closedTimings.clear() | ||
} | ||
|
||
void verify() { | ||
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() {} | ||
} | ||
} |