Skip to content

Commit 1131478

Browse files
Trying to reproduce freeze on CI.
1 parent 5d91afd commit 1131478

File tree

3 files changed

+65
-131
lines changed

3 files changed

+65
-131
lines changed
Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
import java.util.concurrent.Executors
2-
import java.util.concurrent.TimeUnit
3-
41
ext {
52
minJavaVersionForTests = JavaVersion.VERSION_21
63
// Structured concurrency is a preview feature in Java 21. Methods (e.g. ShutdownOnFailure) used in this instrumentation test are no longer available in Java 25, so we set the max version to 24.
@@ -61,65 +58,3 @@ compileJava.configure {
6158
sourceCompatibility = JavaVersion.VERSION_1_8
6259
targetCompatibility = JavaVersion.VERSION_1_8
6360
}
64-
65-
tasks.withType(Test).configureEach {
66-
doFirst {
67-
// This manipulation is requred to move files into folder
68-
// that will be collected by `collect_reports.sh` script.
69-
String buildDir = layout.buildDirectory.asFile.get().absolutePath.replace("dd-trace-java/dd-java-agent",
70-
"dd-trace-java/workspace/dd-java-agent")
71-
72-
def dupmsDir = new File(buildDir, "dumps")
73-
dupmsDir.mkdirs()
74-
75-
// Scheduler to execute logic that will dump threads and heap
76-
def scheduler = Executors.newSingleThreadScheduledExecutor({ r ->
77-
Thread t = new Thread(r, "dump-scheduler")
78-
t.setDaemon(true)
79-
return t
80-
})
81-
82-
// Schedule the dump job:
83-
def future = scheduler.schedule({
84-
try {
85-
def threadDumpFile = new File(dupmsDir, "${System.currentTimeMillis()}-thread-dump.log")
86-
87-
new ProcessBuilder("jcmd", "0", "Thread.print", "-l")
88-
.redirectErrorStream(true)
89-
.redirectOutput(threadDumpFile)
90-
.start().waitFor()
91-
92-
// Collect PIDs of all Java processes:
93-
def jvmProcesses = "jcmd -l".execute().text.readLines()
94-
jvmProcesses.each { p ->
95-
// Process only test executors.
96-
if (!p.contains("Gradle Test Executor")) {
97-
return
98-
}
99-
100-
def pid = p.substring(0, p.indexOf(' '))
101-
def heapDumpFile = "${dupmsDir.absolutePath}/${System.currentTimeMillis()}-${pid}.hprof"
102-
def cmd = "jcmd ${pid} GC.heap_dump ${heapDumpFile}"
103-
cmd.execute().waitFor()
104-
}
105-
} catch (Throwable t) {
106-
logger.warn("Dumping failed: ${t.message}", t)
107-
} finally {
108-
scheduler.shutdown()
109-
}
110-
}, 68, TimeUnit.SECONDS) // You can adjust this line with required delay.
111-
112-
// Store handles for cancellation in doLast:
113-
ext.dumpFuture = future
114-
ext.dumpScheduler = scheduler
115-
}
116-
117-
doLast {
118-
// Cancel if task completed faster than specified timeout.
119-
try {
120-
ext.dumpFuture?.cancel(false)
121-
} finally {
122-
ext.dumpScheduler?.shutdownNow()
123-
}
124-
}
125-
}
Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
import java.util.concurrent.Executors
2-
import java.util.concurrent.TimeUnit
3-
41
muzzle {
52
pass {
63
group = "biz.paluch.redis"
@@ -22,65 +19,3 @@ dependencies {
2219

2320
latestDepTestImplementation group: 'biz.paluch.redis', name: 'lettuce', version: '4.+'
2421
}
25-
26-
tasks.withType(Test).configureEach {
27-
doFirst {
28-
// This manipulation is requred to move files into folder
29-
// that will be collected by `collect_reports.sh` script.
30-
String buildDir = layout.buildDirectory.asFile.get().absolutePath.replace("dd-trace-java/dd-java-agent",
31-
"dd-trace-java/workspace/dd-java-agent")
32-
33-
def dupmsDir = new File(buildDir, "dumps")
34-
dupmsDir.mkdirs()
35-
36-
// Scheduler to execute logic that will dump threads and heap
37-
def scheduler = Executors.newSingleThreadScheduledExecutor({ r ->
38-
Thread t = new Thread(r, "dump-scheduler")
39-
t.setDaemon(true)
40-
return t
41-
})
42-
43-
// Schedule the dump job:
44-
def future = scheduler.schedule({
45-
try {
46-
def threadDumpFile = new File(dupmsDir, "${System.currentTimeMillis()}-thread-dump.log")
47-
48-
new ProcessBuilder("jcmd", "0", "Thread.print", "-l")
49-
.redirectErrorStream(true)
50-
.redirectOutput(threadDumpFile)
51-
.start().waitFor()
52-
53-
// Collect PIDs of all Java processes:
54-
def jvmProcesses = "jcmd -l".execute().text.readLines()
55-
jvmProcesses.each { p ->
56-
// Process only test executors.
57-
if (!p.contains("Gradle Test Executor")) {
58-
return
59-
}
60-
61-
def pid = p.substring(0, p.indexOf(' '))
62-
def heapDumpFile = "${dupmsDir.absolutePath}/${System.currentTimeMillis()}-${pid}.hprof"
63-
def cmd = "jcmd ${pid} GC.heap_dump ${heapDumpFile}"
64-
cmd.execute().waitFor()
65-
}
66-
} catch (Throwable t) {
67-
logger.warn("Dumping failed: ${t.message}", t)
68-
} finally {
69-
scheduler.shutdown()
70-
}
71-
}, 68, TimeUnit.SECONDS) // You can adjust this line with required delay.
72-
73-
// Store handles for cancellation in doLast:
74-
ext.dumpFuture = future
75-
ext.dumpScheduler = scheduler
76-
}
77-
78-
doLast {
79-
// Cancel if task completed faster than specified timeout.
80-
try {
81-
ext.dumpFuture?.cancel(false)
82-
} finally {
83-
ext.dumpScheduler?.shutdownNow()
84-
}
85-
}
86-
}

gradle/configure_tests.gradle

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import java.time.Duration
22
import java.time.temporal.ChronoUnit
3+
import java.util.concurrent.Executors
4+
import java.util.concurrent.TimeUnit
35

46
def isTestingInstrumentation(Project project) {
57
return [
@@ -125,7 +127,7 @@ if (!project.property("activePartition")) {
125127
}
126128
}
127129

128-
tasks.withType(Test) {
130+
tasks.withType(Test).configureEach {
129131
// https://docs.gradle.com/develocity/flaky-test-detection/
130132
// https://docs.gradle.com/develocity/gradle-plugin/current/#test_retry
131133
develocity.testRetry {
@@ -134,3 +136,65 @@ tasks.withType(Test) {
134136
}
135137
}
136138
}
139+
140+
tasks.withType(Test).configureEach {
141+
doFirst {
142+
// This manipulation is requred to move files into folder
143+
// that will be collected by `collect_reports.sh` script.
144+
String buildDir = layout.buildDirectory.asFile.get().absolutePath.replace("dd-trace-java/dd-java-agent",
145+
"dd-trace-java/workspace/dd-java-agent")
146+
147+
def dupmsDir = new File(buildDir, "dumps")
148+
dupmsDir.mkdirs()
149+
150+
// Scheduler to execute logic that will dump threads and heap
151+
def scheduler = Executors.newSingleThreadScheduledExecutor({ r ->
152+
Thread t = new Thread(r, "dump-scheduler")
153+
t.setDaemon(true)
154+
return t
155+
})
156+
157+
// Schedule the dump job:
158+
def future = scheduler.schedule({
159+
try {
160+
def threadDumpFile = new File(dupmsDir, "${System.currentTimeMillis()}-thread-dump.log")
161+
162+
new ProcessBuilder("jcmd", "0", "Thread.print", "-l")
163+
.redirectErrorStream(true)
164+
.redirectOutput(threadDumpFile)
165+
.start().waitFor()
166+
167+
// Collect PIDs of all Java processes:
168+
def jvmProcesses = "jcmd -l".execute().text.readLines()
169+
jvmProcesses.each { p ->
170+
// Process only test executors.
171+
if (!p.contains("Gradle Test Executor")) {
172+
return
173+
}
174+
175+
def pid = p.substring(0, p.indexOf(' '))
176+
def heapDumpFile = "${dupmsDir.absolutePath}/${System.currentTimeMillis()}-${pid}.hprof"
177+
def cmd = "jcmd ${pid} GC.heap_dump ${heapDumpFile}"
178+
cmd.execute().waitFor()
179+
}
180+
} catch (Throwable t) {
181+
logger.warn("Dumping failed: ${t.message}", t)
182+
} finally {
183+
scheduler.shutdown()
184+
}
185+
}, 65, TimeUnit.SECONDS) // You can adjust this line with required delay.
186+
187+
// Store handles for cancellation in doLast:
188+
ext.dumpFuture = future
189+
ext.dumpScheduler = scheduler
190+
}
191+
192+
doLast {
193+
// Cancel if task completed faster than specified timeout.
194+
try {
195+
ext.dumpFuture?.cancel(false)
196+
} finally {
197+
ext.dumpScheduler?.shutdownNow()
198+
}
199+
}
200+
}

0 commit comments

Comments
 (0)