Skip to content

Commit 84b49e9

Browse files
authored
Make the native image smoke test check presence of ExecutionSample events (#6775)
1 parent 67ed8bb commit 84b49e9

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

dd-smoke-tests/spring-boot-3.0-native/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ description = 'Spring Boot 3.0 Native Smoke Tests.'
44

55
dependencies {
66
testImplementation project(':dd-smoke-tests')
7+
testImplementation deps.jmc
78
}
89

910
def testJvm = gradle.startParameter.projectProperties.getOrDefault('testJvm', '')

dd-smoke-tests/spring-boot-3.0-native/src/test/groovy/SpringBootNativeInstrumentationTest.groovy

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
import datadog.smoketest.AbstractServerSmokeTest
22
import okhttp3.Request
3+
import org.openjdk.jmc.common.item.IItemCollection
4+
import org.openjdk.jmc.common.item.ItemFilters
5+
import org.openjdk.jmc.flightrecorder.internal.InvalidJfrFileException
36
import spock.lang.Shared
47
import spock.lang.TempDir
58

9+
import org.openjdk.jmc.flightrecorder.JfrLoaderToolkit
10+
611
import java.nio.file.FileVisitResult
712
import java.nio.file.Files
813
import java.nio.file.Path
914
import java.nio.file.SimpleFileVisitor
1015
import java.nio.file.attribute.BasicFileAttributes
1116
import java.util.concurrent.atomic.AtomicInteger
17+
import java.util.concurrent.locks.LockSupport
1218

1319
class SpringBootNativeInstrumentationTest extends AbstractServerSmokeTest {
1420
@Shared
@@ -57,12 +63,18 @@ class SpringBootNativeInstrumentationTest extends AbstractServerSmokeTest {
5763
def response = client.newCall(new Request.Builder().url(url).get().build()).execute()
5864

5965
then:
66+
def ts = System.nanoTime()
6067
def responseBodyStr = response.body().string()
6168
responseBodyStr != null
6269
responseBodyStr.contains("Hello world")
6370
waitForTraceCount(1)
6471

6572
// sanity test for profiler generating JFR files
73+
// the recording is collected after 1 second of execution
74+
// make sure the app has been up and running for at least 1.5 seconds
75+
while (System.nanoTime() - ts < 1_500_000_000L) {
76+
LockSupport.parkNanos(1_000_000)
77+
}
6678
countJfrs() > 0
6779

6880
when:
@@ -89,7 +101,15 @@ class SpringBootNativeInstrumentationTest extends AbstractServerSmokeTest {
89101
@Override
90102
FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
91103
if (file.toString().endsWith(".jfr")) {
92-
jfrCount.incrementAndGet()
104+
try {
105+
IItemCollection events = JfrLoaderToolkit.loadEvents(file.toFile())
106+
if (events.apply(ItemFilters.type("jdk.ExecutionSample")).hasItems()) {
107+
jfrCount.incrementAndGet()
108+
return FileVisitResult.SKIP_SIBLINGS
109+
}
110+
} catch (InvalidJfrFileException ignored) {
111+
// the recording captured at process exit might be incomplete
112+
}
93113
}
94114
return FileVisitResult.CONTINUE
95115
}

0 commit comments

Comments
 (0)