-
-
Notifications
You must be signed in to change notification settings - Fork 371
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into win-term-size
- Loading branch information
Showing
4 changed files
with
86 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package build | ||
import mill._, javalib._ | ||
|
||
object foo extends JavaModule{ | ||
def runBackgroundLogToConsole: Boolean = false | ||
} |
20 changes: 20 additions & 0 deletions
20
integration/invalidation/run-background/resources/foo/src/foo/Foo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package foo; | ||
import java.io.RandomAccessFile; | ||
import java.nio.channels.FileChannel; | ||
import java.nio.file.*; | ||
public class Foo { | ||
public static void main(String[] args) throws Exception{ | ||
System.out.println("Hello World A!"); | ||
RandomAccessFile raf = new RandomAccessFile(args[0], "rw"); | ||
System.out.println("Hello World B!"); | ||
FileChannel chan = raf.getChannel(); | ||
System.out.println("Hello World C!"); | ||
chan.lock(); | ||
System.out.println("Hello World D!"); | ||
while(true){ | ||
if (!Files.exists(Paths.get(args[1]))) Thread.sleep(1); | ||
else break; | ||
} | ||
System.out.println("Hello World E!"); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
integration/invalidation/run-background/src/RunBackgroundTests.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package mill.integration | ||
|
||
import mill.testkit.UtestIntegrationTestSuite | ||
import java.io.RandomAccessFile | ||
import utest.asserts.{RetryInterval, RetryMax} | ||
import scala.concurrent.duration._ | ||
import utest._ | ||
|
||
// Make sure that `runBackground` subprocesses properly outlive the execution | ||
// that created them, and outlive the Mill process whether terminated naturally | ||
// at the end of `--no-server` or terminated explicitly via `shutdown` | ||
object RunBackgroundTests extends UtestIntegrationTestSuite { | ||
implicit val retryMax: RetryMax = RetryMax(5000.millis) | ||
implicit val retryInterval: RetryInterval = RetryInterval(50.millis) | ||
|
||
def probeLockAvailable(lock: os.Path): Boolean = { | ||
val raf = new RandomAccessFile(lock.toIO, "rw"); | ||
val chan = raf.getChannel(); | ||
chan.tryLock() match { | ||
case null => false | ||
case locked => | ||
locked.release() | ||
true | ||
} | ||
} | ||
|
||
val tests: Tests = Tests { | ||
test("simple") - integrationTest { tester => | ||
import tester._ | ||
val lock = os.temp() | ||
val stop = os.temp() | ||
os.remove(stop) | ||
eval(("foo.runBackground", lock, stop)) | ||
eventually { !probeLockAvailable(lock) } | ||
if (tester.clientServerMode) eval("shutdown") | ||
continually { !probeLockAvailable(lock) } | ||
os.write(stop, "") | ||
eventually { probeLockAvailable(lock) } | ||
} | ||
test("clean") - integrationTest { tester => | ||
if (!mill.main.client.Util.isWindows) { | ||
import tester._ | ||
val lock = os.temp() | ||
val stop = os.temp() | ||
os.remove(stop) | ||
eval(("foo.runBackground", lock, stop)) | ||
eventually { | ||
!probeLockAvailable(lock) | ||
} | ||
|
||
eval(("clean", "foo.runBackground")) | ||
eventually { | ||
probeLockAvailable(lock) | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters