Skip to content

Commit 6a0fae5

Browse files
committed
Adjust tests again.
1 parent 0023c3a commit 6a0fae5

7 files changed

Lines changed: 35 additions & 60 deletions

File tree

dd-smoke-tests/concurrent/src/main/java/datadog/smoketest/concurrent/DemoExecutorService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package datadog.smoketest.concurrent;
22

3-
import static java.util.concurrent.TimeUnit.MILLISECONDS;
3+
import static java.util.concurrent.TimeUnit.SECONDS;
44

55
import io.opentelemetry.instrumentation.annotations.WithSpan;
66
import java.util.concurrent.Callable;
@@ -43,7 +43,7 @@ public Long call() throws ExecutionException, InterruptedException {
4343
public void close() {
4444
executorService.shutdown();
4545
try {
46-
if (!executorService.awaitTermination(800, MILLISECONDS)) {
46+
if (!executorService.awaitTermination(10, SECONDS)) {
4747
executorService.shutdownNow();
4848
}
4949
} catch (InterruptedException e) {

dd-smoke-tests/concurrent/src/main/java/datadog/smoketest/concurrent/DemoForkJoin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ public DemoForkJoin() {
1111
forkJoinPool = new ForkJoinPool();
1212
}
1313

14-
@WithSpan("compute")
1514
@Override
1615
public long computeFibonacci(int n) {
1716
return forkJoinPool.invoke(new FibonacciTask(n));
@@ -24,6 +23,7 @@ public FibonacciTask(int n) {
2423
this.n = n;
2524
}
2625

26+
@WithSpan("compute")
2727
@Override
2828
protected Long compute() {
2929
if (n <= 1) {

dd-smoke-tests/concurrent/src/test/groovy/datadog/smoketest/AbstractDemoTest.groovy

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package datadog.smoketest
22

3+
import static java.util.concurrent.TimeUnit.SECONDS
34
import datadog.trace.test.agent.decoder.DecodedTrace
4-
55
import java.util.function.Function
66

77
abstract class AbstractDemoTest extends AbstractSmokeTest {
@@ -30,32 +30,37 @@ abstract class AbstractDemoTest extends AbstractSmokeTest {
3030
protected static Function<DecodedTrace, Boolean> checkTrace() {
3131
return {
3232
trace ->
33-
// Get root span
34-
def rootSpan = trace.spans.find { it.name == 'main' }
35-
if (!rootSpan) {
33+
// Check for 'main' span
34+
def mainSpan = trace.spans.find { it.name == 'main' }
35+
if (!mainSpan) {
3636
return false
3737
}
3838
// Check that there are only 'main' and 'compute' spans
3939
def otherSpans = trace.spans.findAll { it.name != 'main' && it.name != 'compute' }
4040
if (!otherSpans.isEmpty()) {
4141
return false
4242
}
43-
// Check every 'compute' span is either a child of the root span or another 'compute' span
43+
// Check that every 'compute' span is in the same trace and is either a child of the 'main' span or another 'compute' span
4444
def computeSpans = trace.spans.findAll { it.name == 'compute' }
4545
if (computeSpans.isEmpty()) {
4646
return false
4747
}
4848
return computeSpans.every {
49-
// Check same trace
50-
if (it.traceId != rootSpan.traceId) {
49+
if (it.traceId != mainSpan.traceId) {
5150
return false
5251
}
53-
// Check parent
54-
if (it.parentId != rootSpan.spanId && trace.spans.find(s -> s.spanId == it.parentId).name != 'compute') {
52+
if (it.parentId != mainSpan.spanId && trace.spans.find(s -> s.spanId == it.parentId).name != 'compute') {
5553
return false
5654
}
5755
return true
5856
}
5957
}
6058
}
59+
60+
protected void receivedCorrectTrace() {
61+
waitForTrace(defaultPoll, checkTrace())
62+
assert traceCount.get() == 1
63+
assert testedProcess.waitFor(TIMEOUT_SECS, SECONDS)
64+
assert testedProcess.exitValue() == 0
65+
}
6166
}
Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,12 @@
11
package datadog.smoketest
22

3-
import static java.util.concurrent.TimeUnit.SECONDS
4-
53
class DemoExecutorServiceTest extends AbstractDemoTest {
6-
@Override
74
protected List<String> getTestArguments() {
85
return ["executorService"]
96
}
107

11-
def 'receive one expected trace for ExecutorService'() {
12-
when:
13-
waitForTrace(defaultPoll, checkTrace())
14-
15-
then:
16-
traceCount.get() == 1
17-
18-
and:
19-
assert testedProcess.waitFor(TIMEOUT_SECS, SECONDS)
20-
assert testedProcess.exitValue() == 0
8+
def 'receive one correct trace when using ExecutorService'() {
9+
expect:
10+
receivedCorrectTrace()
2111
}
2212
}
Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,12 @@
11
package datadog.smoketest
22

3-
import static java.util.concurrent.TimeUnit.SECONDS
4-
53
class DemoForkJoinTest extends AbstractDemoTest {
6-
@Override
74
protected List<String> getTestArguments() {
85
return ["forkJoin"]
96
}
107

11-
def 'receive one expected trace for ExecutorService'() {
12-
when:
13-
waitForTrace(defaultPoll, checkTrace())
14-
15-
then:
16-
traceCount.get() == 1
17-
18-
and:
19-
assert testedProcess.waitFor(TIMEOUT_SECS, SECONDS)
20-
assert testedProcess.exitValue() == 0
8+
def 'receive one correct trace when using ForkJoin'() {
9+
expect:
10+
receivedCorrectTrace()
2111
}
2212
}

dd-smoke-tests/concurrent/src/test/groovy/datadog/smoketest/DemoMixedConcurrencyTest.groovy

Lines changed: 0 additions & 22 deletions
This file was deleted.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package datadog.smoketest
2+
3+
class DemoMultipleConcurrenciesTest extends AbstractDemoTest {
4+
protected List<String> getTestArguments() {
5+
return ["executorService", "forkJoin"]
6+
}
7+
8+
def 'receive one correct trace when using multiple concurrency strategies (ExecutorService and ForkJoin)'() {
9+
expect:
10+
receivedCorrectTrace()
11+
}
12+
}

0 commit comments

Comments
 (0)