Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run Future tests sequentially, not concurrently #359

Merged
merged 2 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions utest/src-native/utest/PlatformShims.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion utest/src/utest/TestRunner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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:_*)
}

Expand Down
17 changes: 17 additions & 0 deletions utest/test/src/test/utest/FutureTest.scala
Original file line number Diff line number Diff line change
@@ -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)
}
}
}
Loading