From d5cde986540e11aac78a80cb2733d8e5fe065678 Mon Sep 17 00:00:00 2001 From: Eugene Yokota Date: Sun, 23 Jul 2023 00:59:44 -0400 Subject: [PATCH 1/2] Revert "Add timeout to scripted statements" This reverts commit 155526fb116794a3e348dbf7d629deeeb4a9b84a. --- .../sbt/scriptedtest/BatchScriptRunner.scala | 52 +++++++------------ .../sbt/scriptedtest/ScriptedTests.scala | 9 +--- 2 files changed, 22 insertions(+), 39 deletions(-) diff --git a/scripted-sbt-redux/src/main/scala/sbt/scriptedtest/BatchScriptRunner.scala b/scripted-sbt-redux/src/main/scala/sbt/scriptedtest/BatchScriptRunner.scala index 8c0a4df86..da7d9bb82 100644 --- a/scripted-sbt-redux/src/main/scala/sbt/scriptedtest/BatchScriptRunner.scala +++ b/scripted-sbt-redux/src/main/scala/sbt/scriptedtest/BatchScriptRunner.scala @@ -9,10 +9,8 @@ package sbt package scriptedtest -import java.util.concurrent.{ Executors, TimeUnit, TimeoutException } - import scala.collection.mutable -import scala.concurrent.duration._ + import sbt.internal.scripted._ private[sbt] object BatchScriptRunner { @@ -20,9 +18,8 @@ private[sbt] object BatchScriptRunner { } /** Defines an alternative script runner that allows batch execution. */ -private[sbt] class BatchScriptRunner extends ScriptRunner with AutoCloseable { +private[sbt] class BatchScriptRunner extends ScriptRunner { import BatchScriptRunner.States - private[this] val service = Executors.newCachedThreadPool() /** Defines a method to run batched execution. * @@ -44,35 +41,26 @@ private[sbt] class BatchScriptRunner extends ScriptRunner with AutoCloseable { } } - private val timeout = 5.minutes def processStatement(handler: StatementHandler, statement: Statement, states: States): Unit = { val state = states(handler).asInstanceOf[handler.State] - val nextStateFuture = service.submit( - () => - try Right(handler(statement.command, statement.arguments, state)) - catch { case e: Exception => Left(e) } - ) - try { - nextStateFuture.get(timeout.toMillis, TimeUnit.MILLISECONDS) match { - case Left(err) => - if (statement.successExpected) { - err match { - case t: TestFailed => - throw new TestException(statement, "Command failed: " + t.getMessage, null) - case _ => throw new TestException(statement, "Command failed", err) - } - } else - () - case Right(s) => - if (statement.successExpected) - 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) + val nextState = + try Right(handler(statement.command, statement.arguments, state)) + catch { case e: Exception => Left(e) } + nextState match { + case Left(err) => + if (statement.successExpected) { + err match { + case t: TestFailed => + throw new TestException(statement, "Command failed: " + t.getMessage, null) + case _ => throw new TestException(statement, "Command failed", err) + } + } else + () + case Right(s) => + if (statement.successExpected) + states(handler) = s + else + throw new TestException(statement, "Command succeeded but failure was expected", null) } } - - override def close(): Unit = service.shutdown() } diff --git a/scripted-sbt-redux/src/main/scala/sbt/scriptedtest/ScriptedTests.scala b/scripted-sbt-redux/src/main/scala/sbt/scriptedtest/ScriptedTests.scala index 803b14610..a85d6eaa6 100644 --- a/scripted-sbt-redux/src/main/scala/sbt/scriptedtest/ScriptedTests.scala +++ b/scripted-sbt-redux/src/main/scala/sbt/scriptedtest/ScriptedTests.scala @@ -69,8 +69,7 @@ final class ScriptedTests( val handlers = createScriptedHandlers(testDirectory, buffer, prop) val runner = new BatchScriptRunner val states = new mutable.HashMap[StatementHandler, StatementHandler#State]() - try commonRunTest(label, testDirectory, prescripted, handlers, runner, states, buffer) - finally runner.close() + commonRunTest(label, testDirectory, prescripted, handlers, runner, states, buffer) } runOrHandleDisabled(label, testDirectory, singleTestRunner, buffer) } @@ -260,10 +259,7 @@ final class ScriptedTests( } try runBatchTests - finally { - runner.cleanUpHandlers(seqHandlers, states) - runner.close() - } + finally runner.cleanUpHandlers(seqHandlers, states) } private def runOrHandleDisabled( @@ -316,7 +312,6 @@ final class ScriptedTests( case null | _: SocketException => log.error(s" Cause of test exception: ${t.getMessage}") case _ => if (!pending) t.printStackTrace() } - log.play() } if (pending) None else Some(label) } From 4c96f45b20d0fb50aa91f777e6728823a5d1d046 Mon Sep 17 00:00:00 2001 From: Eugene Yokota Date: Sun, 23 Jul 2023 01:01:23 -0400 Subject: [PATCH 2/2] Keep the close method --- .../src/main/scala/sbt/scriptedtest/BatchScriptRunner.scala | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripted-sbt-redux/src/main/scala/sbt/scriptedtest/BatchScriptRunner.scala b/scripted-sbt-redux/src/main/scala/sbt/scriptedtest/BatchScriptRunner.scala index da7d9bb82..28161edb7 100644 --- a/scripted-sbt-redux/src/main/scala/sbt/scriptedtest/BatchScriptRunner.scala +++ b/scripted-sbt-redux/src/main/scala/sbt/scriptedtest/BatchScriptRunner.scala @@ -18,7 +18,7 @@ private[sbt] object BatchScriptRunner { } /** Defines an alternative script runner that allows batch execution. */ -private[sbt] class BatchScriptRunner extends ScriptRunner { +private[sbt] class BatchScriptRunner extends ScriptRunner with AutoCloseable { import BatchScriptRunner.States /** Defines a method to run batched execution. @@ -63,4 +63,6 @@ private[sbt] class BatchScriptRunner extends ScriptRunner { throw new TestException(statement, "Command succeeded but failure was expected", null) } } + + override def close(): Unit = () }