Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexarchambault committed Oct 8, 2024
1 parent c58bac7 commit 11e57d4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,27 @@ import mill.testkit.UtestIntegrationTestSuite
import utest._

import java.io.ByteArrayOutputStream
import java.util.concurrent.CountDownLatch
import java.util.concurrent.{CountDownLatch, Executors}

import scala.concurrent.Await
import scala.concurrent.duration.Duration
import scala.concurrent.{Await, ExecutionContext, Future}

object OutputDirectoryLockTests extends UtestIntegrationTestSuite {

private val pool = Executors.newCachedThreadPool()
private val ec = ExecutionContext.fromExecutorService(pool)

override def utestAfterAll(): Unit = {
pool.shutdown()
}

def tests: Tests = Tests {
test("basic") - integrationTest { tester =>
import tester._
val signalFile = workspacePath / "do-wait"
System.err.println("Spawning blocking task")
val blocksFuture = evalAsync(("show", "blockWhileExists", "--path", signalFile), check = true)
val blocksFuture =
Future(eval(("show", "blockWhileExists", "--path", signalFile), check = true))(ec)
while (!os.exists(signalFile) && !blocksFuture.isCompleted)
Thread.sleep(100L)
if (os.exists(signalFile))
Expand All @@ -43,20 +51,22 @@ object OutputDirectoryLockTests extends UtestIntegrationTestSuite {
val lock = new CountDownLatch(1)
val stderr = new ByteArrayOutputStream
var success = false
val futureWaitingRes = evalAsync(
testCommand,
stderr = os.ProcessOutput {
val expectedMessage =
"Another Mill process is running tasks, waiting for it to be done..."

(bytes, len) =>
stderr.write(bytes, 0, len)
val output = new String(stderr.toByteArray)
if (output.contains(expectedMessage))
lock.countDown()
},
check = true
)
val futureWaitingRes = Future {
eval(
testCommand,
stderr = os.ProcessOutput {
val expectedMessage =
"Another Mill process is running tasks, waiting for it to be done..."

(bytes, len) =>
stderr.write(bytes, 0, len)
val output = new String(stderr.toByteArray)
if (output.contains(expectedMessage))
lock.countDown()
},
check = true
)
}(ec)
try {
lock.await()
success = true
Expand Down
48 changes: 0 additions & 48 deletions testkit/src/mill/testkit/IntegrationTester.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ import mill.eval.Evaluator
import mill.resolve.SelectMode
import ujson.Value

import java.util.concurrent.atomic.AtomicInteger

import scala.concurrent.{Future, Promise}
import scala.util.Try

/**
* Helper meant for executing Mill integration tests, which runs Mill in a subprocess
* against a folder with a `build.mill` and project files. Provides APIs such as [[eval]]
Expand Down Expand Up @@ -96,49 +91,6 @@ object IntegrationTester {
)
}

private val evalAsyncCounter = new AtomicInteger
def evalAsync(
cmd: os.Shellable,
env: Map[String, String] = millTestSuiteEnv,
cwd: os.Path = workspacePath,
stdin: os.ProcessInput = os.Pipe,
stdout: os.ProcessOutput = os.Pipe,
stderr: os.ProcessOutput = os.Pipe,
mergeErrIntoOut: Boolean = false,
timeout: Long = -1,
check: Boolean = false,
propagateEnv: Boolean = true,
timeoutGracePeriod: Long = 100
): Future[IntegrationTester.EvalResult] = {

val promise = Promise[IntegrationTester.EvalResult]()

val thread = new Thread(s"mill-test-background-eval-${evalAsyncCounter.incrementAndGet()}") {
setDaemon(true)
override def run(): Unit =
promise.complete {
Try {
eval(
cmd = cmd,
env = env,
cwd = cwd,
stdin = stdin,
stdout = stdout,
stderr = stderr,
mergeErrIntoOut = mergeErrIntoOut,
timeout = timeout,
check = check,
propagateEnv = propagateEnv,
timeoutGracePeriod = timeoutGracePeriod
)
}
}
}
thread.start()

promise.future
}

def millTestSuiteEnv: Map[String, String] = Map("MILL_TEST_SUITE" -> this.getClass().toString())

/**
Expand Down

0 comments on commit 11e57d4

Please sign in to comment.