From b7681caf43dfaba89a48f9e2fb198496f5503669 Mon Sep 17 00:00:00 2001 From: Arman Bilge Date: Thu, 9 Jan 2025 03:47:59 +0000 Subject: [PATCH 1/2] Run `Future` tests sequentially, not concurrently --- utest/src/utest/TestRunner.scala | 4 +++- utest/test/src/test/utest/FutureTest.scala | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 utest/test/src/test/utest/FutureTest.scala diff --git a/utest/src/utest/TestRunner.scala b/utest/src/utest/TestRunner.scala index 5dbc237a..c2cde1be 100644 --- a/utest/src/utest/TestRunner.scala +++ b/utest/src/utest/TestRunner.scala @@ -171,7 +171,9 @@ object TestRunner { case HTree.Leaf(f) => f().map(HTree.Leaf(_)) case HTree.Node(v, children @ _*) => for{ - childValues <- Future.traverse(children.toSeq)(evaluateFutureTree(_)) + childValues <- children.foldLeft(Future.successful(List.newBuilder[HTree[N, L]])) { (fb, c) => + fb.flatMap(b => evaluateFutureTree(c).map(b += _)) + }.map(_.result()) } yield HTree.Node(v, childValues:_*) } diff --git a/utest/test/src/test/utest/FutureTest.scala b/utest/test/src/test/utest/FutureTest.scala new file mode 100644 index 00000000..a4c529bf --- /dev/null +++ b/utest/test/src/test/utest/FutureTest.scala @@ -0,0 +1,17 @@ +package test.utest +import utest._ +import concurrent.{Future, ExecutionContext} + +object FutureTest extends TestSuite { + implicit val ec: ExecutionContext = ExecutionContext.global + @volatile var flag = false + + def tests = TestSuite { + test("runs before next test"){ + Future { flag = true } + } + test("previous test ran first"){ + assert(flag) + } + } +} From e3d17fcb3db9ebf2da389794ce59742ac99f8f95 Mon Sep 17 00:00:00 2001 From: Arman Bilge Date: Thu, 9 Jan 2025 07:30:47 +0000 Subject: [PATCH 2/2] Fix native --- utest/src-native/utest/PlatformShims.scala | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/utest/src-native/utest/PlatformShims.scala b/utest/src-native/utest/PlatformShims.scala index 457606d2..8f076f04 100644 --- a/utest/src-native/utest/PlatformShims.scala +++ b/utest/src-native/utest/PlatformShims.scala @@ -2,22 +2,15 @@ package utest // Taken from the implementation for JS -import scala.concurrent.Future +import scala.concurrent.{Await, Future} +import concurrent.duration._ import scala.scalanative.reflect.Reflect /** * Platform specific stuff that differs between JVM, JS and Native */ object PlatformShims { - def await[T](f: Future[T]): T = { - scala.scalanative.runtime.loop() - f.value match { - case Some(v) => v.get - case None => throw new IllegalStateException( - "Test that returns Future must be run asynchronously in Scala Native, see TestTreeSeq::runAsync" - ) - } - } + def await[T](f: Future[T]): T = Await.result(f, Duration.Inf) type EnableReflectiveInstantiation = scala.scalanative.reflect.annotation.EnableReflectiveInstantiation