aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorvsalvis <salvisbergvera@gmail.com>2015-05-12 11:15:29 +0200
committervsalvis <salvisbergvera@gmail.com>2015-05-12 11:19:35 +0200
commitef22b1d0f878e97a7602dabd1a90ba871bf1fccb (patch)
tree32a2d0838f2661c2200f4fddbd49b46b8ecf8cb0 /test
parent7e3595d1f7efa34ef3ea2409529643cd8864e926 (diff)
downloaddotty-ef22b1d0f878e97a7602dabd1a90ba871bf1fccb.tar.gz
dotty-ef22b1d0f878e97a7602dabd1a90ba871bf1fccb.tar.bz2
dotty-ef22b1d0f878e97a7602dabd1a90ba871bf1fccb.zip
More robust partest/test switching for concurrent sbt instances
Diffstat (limited to 'test')
-rw-r--r--test/test/CompilerTest.scala32
1 files changed, 17 insertions, 15 deletions
diff --git a/test/test/CompilerTest.scala b/test/test/CompilerTest.scala
index d710a26d8..0e5c9a6b4 100644
--- a/test/test/CompilerTest.scala
+++ b/test/test/CompilerTest.scala
@@ -14,9 +14,9 @@ import org.junit.Test
/** This class has two modes: it can directly run compiler tests, or it can
* generate the necessary file structure for partest in the directory
* DPConfig.testRoot. Both modes are regular JUnit tests. Which mode is used
- * depends on the existence of the tests/runPartest.flag file which is created
- * by sbt to trigger partest generation. Sbt can then run partest on the
- * generated sources.
+ * depends on the existence of the tests/locks/partest-ppid.lock file which is
+ * created by sbt to trigger partest generation. Sbt will then run partest on
+ * the generated sources.
*
* Through overriding the partestableXX methods, tests can always be run as
* JUnit compiler tests. Run tests cannot be run by JUnit, only by partest.
@@ -45,18 +45,20 @@ abstract class CompilerTest extends DottyTest {
def partestableList(testName: String, files: List[String], args: List[String], xerrors: Int) = true
val generatePartestFiles = {
- val partestLockFile = "." + JFile.separator + "tests" + JFile.separator + "partest.lock"
- try {
- val partestLock = new RandomAccessFile(partestLockFile, "rw").getChannel.tryLock
- if (partestLock != null) { // file not locked by sbt -> don't generate partest
- partestLock.release
- false
- } else true
- } catch {
- // if sbt doesn't fork in Test, the tryLock request will throw instead of
- // returning null, because locks are per JVM, not per thread
- case ex: java.nio.channels.OverlappingFileLockException => true
- }
+ /* Because we fork in test, the JVM in which this JUnit test runs has a
+ * different pid from the one that started the partest. But the forked VM
+ * receives the pid of the parent as system property. If the lock file
+ * exists, the parent is requesting partest generation. This mechanism
+ * allows one sbt instance to run test (JUnit only) and another partest.
+ * We cannot run two instances of partest at the same time, because they're
+ * writing to the same directories. The sbt lock file generation prevents
+ * this.
+ */
+ val pid = System.getProperty("partestParentID")
+ if (pid == null)
+ false
+ else
+ new JFile("." + JFile.separator + "tests" + JFile.separator + "locks" + JFile.separator + s"partest-$pid.lock").exists
}
// Delete generated files from previous run