Make test-directory multi-threaded proof
When running tests using sbt from CLI, all the test
suites are running in parallel threads. Test directories
need to include the thread name so to make sure they do
not randomly fail for conflicting directory names.
Change-Id: Ie37ab60e8d620565b091fc9d3979a3df6a46e50c
diff --git a/src/test/scala/com/googlesource/gerrit/plugins/analytics/test/GitTestCase.scala b/src/test/scala/com/googlesource/gerrit/plugins/analytics/test/GitTestCase.scala
index 3bf36ae..8a1dcf7 100644
--- a/src/test/scala/com/googlesource/gerrit/plugins/analytics/test/GitTestCase.scala
+++ b/src/test/scala/com/googlesource/gerrit/plugins/analytics/test/GitTestCase.scala
@@ -36,6 +36,7 @@
package com.googlesource.gerrit.plugins.analytics.test
import java.io.{File, PrintWriter}
+import java.nio.file.Files
import java.text.MessageFormat
import java.util.Date
@@ -92,10 +93,7 @@
* @throws GitAPIException
*/
protected def initRepo: File = {
- val tmpDir = System.getProperty("java.io.tmpdir")
- assert(tmpDir != null, "java.io.tmpdir was null")
- val dir = new File(tmpDir, "git-test-case-" + System.nanoTime)
- assert(dir.mkdir)
+ val dir = Files.createTempDirectory(threadSpecificDirectoryPrefix).toFile
Git.init.setDirectory(dir).setBare(false).call
val repo = new File(dir, Constants.DOT_GIT)
assert(repo.exists)
@@ -103,6 +101,9 @@
repo
}
+ private def threadSpecificDirectoryPrefix =
+ "git-test-case-" + Thread.currentThread().getName.replaceAll("~[0-9a-zA-Z]", "_") + System.nanoTime
+
/**
* Create branch with name and checkout
*