Skip to content

Commit 8e344c7

Browse files
authored
Build: Capture jcstress output in a log file (#2890)
The jcstress output is pretty verbose and prints a lot to the console. This change captures the output in a log file. In case of a test failure, the output is logged to the console, but only in case of a failure.
1 parent 19b916d commit 8e344c7

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

persistence/nosql/idgen/impl/build.gradle.kts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
* under the License.
1818
*/
1919

20+
import com.github.erizo.gradle.JcstressTask
21+
import java.io.FileOutputStream
22+
import java.nio.file.Files
23+
2024
plugins {
2125
id("org.kordamp.gradle.jandex")
2226
alias(libs.plugins.jmh)
@@ -72,7 +76,7 @@ tasks.named("check") { dependsOn("jcstress") }
7276

7377
jcstress { jcstressDependency = libs.jcstress.core.get().toString() }
7478

75-
tasks.named("jcstress") {
79+
tasks.named<JcstressTask>("jcstress") {
7680
inputs.properties(
7781
System.getProperties()
7882
.mapKeys { it.key.toString() }
@@ -85,4 +89,25 @@ tasks.named("jcstress") {
8589
inputs.files(jcstressRuntime)
8690
inputs.files(configurations.runtimeClasspath)
8791
outputs.dir(layout.buildDirectory.dir("reports/jcstress"))
92+
93+
if (!System.getProperty("jcstress-no-capture").toBoolean()) {
94+
// Capture jcstress output in a log file, dump that in case of a failure.
95+
96+
val logDir = project.layout.buildDirectory.dir("reports/jcstress").get().asFile
97+
val logFile = File(logDir, "jcstress.log")
98+
var logStream: FileOutputStream? = null
99+
100+
actions.addFirst {
101+
logStream = FileOutputStream(logFile)
102+
standardOutput = logStream
103+
errorOutput = logStream
104+
}
105+
106+
actions.addLast {
107+
logStream?.close()
108+
if (state.failure != null) {
109+
logger.error("jcstress output\n{}", Files.readString(logFile.toPath()))
110+
}
111+
}
112+
}
88113
}

0 commit comments

Comments
 (0)