Skip to content

Commit fb98e83

Browse files
committed
Robuster FileLock test to prevent exception if fork in Test is ever disabled
1 parent 346ad4f commit fb98e83

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

project/Build.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import sbt.Keys._
22
import sbt._
33
import java.io.{ RandomAccessFile, File }
4-
import java.nio.channels.{ FileLock, OverlappingFileLockException }
4+
import java.nio.channels.FileLock
5+
56
object DottyBuild extends Build {
67

78
val TRAVIS_BUILD = "dotty.travis.build"

test/test/CompilerTest.scala

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,17 @@ abstract class CompilerTest extends DottyTest {
4242

4343
val generatePartestFiles = {
4444
val partestLockFile = "." + JFile.separator + "tests" + JFile.separator + "partest.lock"
45-
val partestLock = new RandomAccessFile(partestLockFile, "rw").getChannel.tryLock
46-
if (partestLock != null) { // file not locked by sbt -> don't generate partest
47-
partestLock.release
48-
false
49-
} else true
45+
try {
46+
val partestLock = new RandomAccessFile(partestLockFile, "rw").getChannel.tryLock
47+
if (partestLock != null) { // file not locked by sbt -> don't generate partest
48+
partestLock.release
49+
false
50+
} else true
51+
} catch {
52+
// if sbt doesn't fork in Test, the tryLock request will throw instead of
53+
// returning null, because locks are per JVM, not per thread
54+
case ex: java.nio.channels.OverlappingFileLockException => true
55+
}
5056
}
5157

5258
// Delete generated files from previous run

0 commit comments

Comments
 (0)