mirror of https://github.com/sbt/sbt.git
Merge pull request #7336 from eed3si9n/wip/revert_timeout
Revert scripted timeout
This commit is contained in:
commit
8d818e2da9
|
|
@ -9,10 +9,8 @@
|
||||||
package sbt
|
package sbt
|
||||||
package scriptedtest
|
package scriptedtest
|
||||||
|
|
||||||
import java.util.concurrent.{ Executors, TimeUnit, TimeoutException }
|
|
||||||
|
|
||||||
import scala.collection.mutable
|
import scala.collection.mutable
|
||||||
import scala.concurrent.duration._
|
|
||||||
import sbt.internal.scripted._
|
import sbt.internal.scripted._
|
||||||
|
|
||||||
private[sbt] object BatchScriptRunner {
|
private[sbt] object BatchScriptRunner {
|
||||||
|
|
@ -22,7 +20,6 @@ private[sbt] object BatchScriptRunner {
|
||||||
/** Defines an alternative script runner that allows batch execution. */
|
/** Defines an alternative script runner that allows batch execution. */
|
||||||
private[sbt] class BatchScriptRunner extends ScriptRunner with AutoCloseable {
|
private[sbt] class BatchScriptRunner extends ScriptRunner with AutoCloseable {
|
||||||
import BatchScriptRunner.States
|
import BatchScriptRunner.States
|
||||||
private[this] val service = Executors.newCachedThreadPool()
|
|
||||||
|
|
||||||
/** Defines a method to run batched execution.
|
/** Defines a method to run batched execution.
|
||||||
*
|
*
|
||||||
|
|
@ -44,35 +41,28 @@ private[sbt] class BatchScriptRunner extends ScriptRunner with AutoCloseable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private val timeout = 5.minutes
|
|
||||||
def processStatement(handler: StatementHandler, statement: Statement, states: States): Unit = {
|
def processStatement(handler: StatementHandler, statement: Statement, states: States): Unit = {
|
||||||
val state = states(handler).asInstanceOf[handler.State]
|
val state = states(handler).asInstanceOf[handler.State]
|
||||||
val nextStateFuture = service.submit(
|
val nextState =
|
||||||
() =>
|
try Right(handler(statement.command, statement.arguments, state))
|
||||||
try Right(handler(statement.command, statement.arguments, state))
|
catch { case e: Exception => Left(e) }
|
||||||
catch { case e: Exception => Left(e) }
|
nextState match {
|
||||||
)
|
case Left(err) =>
|
||||||
try {
|
if (statement.successExpected) {
|
||||||
nextStateFuture.get(timeout.toMillis, TimeUnit.MILLISECONDS) match {
|
err match {
|
||||||
case Left(err) =>
|
case t: TestFailed =>
|
||||||
if (statement.successExpected) {
|
throw new TestException(statement, "Command failed: " + t.getMessage, null)
|
||||||
err match {
|
case _ => throw new TestException(statement, "Command failed", err)
|
||||||
case t: TestFailed =>
|
}
|
||||||
throw new TestException(statement, "Command failed: " + t.getMessage, null)
|
} else
|
||||||
case _ => throw new TestException(statement, "Command failed", err)
|
()
|
||||||
}
|
case Right(s) =>
|
||||||
} else
|
if (statement.successExpected)
|
||||||
()
|
states(handler) = s
|
||||||
case Right(s) =>
|
else
|
||||||
if (statement.successExpected)
|
throw new TestException(statement, "Command succeeded but failure was expected", null)
|
||||||
states(handler) = s
|
|
||||||
else
|
|
||||||
throw new TestException(statement, "Command succeeded but failure was expected", null)
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
case e: TimeoutException => throw new TestException(statement, "Command timed out", e)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override def close(): Unit = service.shutdown()
|
override def close(): Unit = ()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -69,8 +69,7 @@ final class ScriptedTests(
|
||||||
val handlers = createScriptedHandlers(testDirectory, buffer, prop)
|
val handlers = createScriptedHandlers(testDirectory, buffer, prop)
|
||||||
val runner = new BatchScriptRunner
|
val runner = new BatchScriptRunner
|
||||||
val states = new mutable.HashMap[StatementHandler, StatementHandler#State]()
|
val states = new mutable.HashMap[StatementHandler, StatementHandler#State]()
|
||||||
try commonRunTest(label, testDirectory, prescripted, handlers, runner, states, buffer)
|
commonRunTest(label, testDirectory, prescripted, handlers, runner, states, buffer)
|
||||||
finally runner.close()
|
|
||||||
}
|
}
|
||||||
runOrHandleDisabled(label, testDirectory, singleTestRunner, buffer)
|
runOrHandleDisabled(label, testDirectory, singleTestRunner, buffer)
|
||||||
}
|
}
|
||||||
|
|
@ -260,10 +259,7 @@ final class ScriptedTests(
|
||||||
}
|
}
|
||||||
|
|
||||||
try runBatchTests
|
try runBatchTests
|
||||||
finally {
|
finally runner.cleanUpHandlers(seqHandlers, states)
|
||||||
runner.cleanUpHandlers(seqHandlers, states)
|
|
||||||
runner.close()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private def runOrHandleDisabled(
|
private def runOrHandleDisabled(
|
||||||
|
|
@ -316,7 +312,6 @@ final class ScriptedTests(
|
||||||
case null | _: SocketException => log.error(s" Cause of test exception: ${t.getMessage}")
|
case null | _: SocketException => log.error(s" Cause of test exception: ${t.getMessage}")
|
||||||
case _ => if (!pending) t.printStackTrace()
|
case _ => if (!pending) t.printStackTrace()
|
||||||
}
|
}
|
||||||
log.play()
|
|
||||||
}
|
}
|
||||||
if (pending) None else Some(label)
|
if (pending) None else Some(label)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue