Skip to content

Commit a8a85d1

Browse files
committed
fix: Don't use the the shared tempdir as it is shared for every test
This causes all tests to use the same user preference folder, possibly increasing the chance of this issue happening.
1 parent e083523 commit a8a85d1

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

dd-java-agent/agent-ci-visibility/civisibility-test-fixtures/src/main/groovy/datadog/trace/civisibility/CiVisibilitySmokeTest.groovy

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import datadog.trace.api.config.CiVisibilityConfig
66
import datadog.trace.api.config.GeneralConfig
77
import datadog.trace.api.config.TraceInstrumentationConfig
88
import datadog.trace.api.config.TracerConfig
9+
import java.nio.file.Paths
910
import spock.lang.Shared
1011
import spock.lang.Specification
1112
import spock.lang.TempDir
@@ -28,10 +29,6 @@ abstract class CiVisibilitySmokeTest extends Specification {
2829
@TempDir
2930
protected Path prefsDir
3031

31-
@Shared
32-
@TempDir
33-
protected Path prefsDirShared
34-
3532
protected static String buildJavaHome() {
3633
if (Jvm.current.isJava8()) {
3734
return System.getenv("JAVA_8_HOME")
@@ -111,10 +108,16 @@ abstract class CiVisibilitySmokeTest extends Specification {
111108
* `setupSpec()`.
112109
*/
113110
protected String preventJulPrefsFileLock() {
114-
String prefsPath = (prefsDir ?: prefsDirShared).toAbsolutePath()
111+
String prefsPath = (prefsDir ?: tempUserPrefsPath()).toAbsolutePath()
115112
return "-Djava.util.prefs.userRoot=$prefsPath".toString()
116113
}
117114

115+
private static Path tempUserPrefsPath() {
116+
String uniqueId = "${System.currentTimeMillis()}_${System.nanoTime()}_${Thread.currentThread().id}"
117+
Path prefsPath = Paths.get(System.getProperty("java.io.tmpdir"), "gradle-test-userPrefs", uniqueId)
118+
return prefsPath
119+
}
120+
118121
protected verifyEventsAndCoverages(String projectName, String toolchain, String toolchainVersion, List<Map<String, Object>> events, List<Map<String, Object>> coverages, List<String> additionalDynamicTags = []) {
119122
def additionalReplacements = ["content.meta.['test.toolchain']": "$toolchain:$toolchainVersion"]
120123

0 commit comments

Comments
 (0)