From 4e337eea638f5febb162200b66c713588a92bff4 Mon Sep 17 00:00:00 2001 From: Corey O'Connor Date: Tue, 26 Nov 2024 08:02:27 +0000 Subject: [PATCH] add an order to apply on sequential --- .../src/main/scala/izumi/distage/model/PlannerInput.scala | 1 + .../src/main/scala/izumi/distage/model/plan/Plan.scala | 2 ++ .../scala/izumi/distage/testkit/model/TestGroup.scala | 8 ++++++++ .../main/scala/izumi/distage/testkit/model/TestTree.scala | 5 +++++ .../distage/testkit/runner/impl/DistageTestRunner.scala | 7 +++++++ .../izumi/distage/testkit/runner/impl/TestPlanner.scala | 5 +++++ .../distage/testkit/runner/impl/TestTreeRunner.scala | 2 ++ .../testkit/runner/impl/services/ExtParTraverse.scala | 6 +++--- 8 files changed, 33 insertions(+), 3 deletions(-) diff --git a/distage/distage-core-api/src/main/scala/izumi/distage/model/PlannerInput.scala b/distage/distage-core-api/src/main/scala/izumi/distage/model/PlannerInput.scala index 82053e2c2e..d5880f2858 100644 --- a/distage/distage-core-api/src/main/scala/izumi/distage/model/PlannerInput.scala +++ b/distage/distage-core-api/src/main/scala/izumi/distage/model/PlannerInput.scala @@ -86,4 +86,5 @@ object PlannerInput { def apply(bindings: ModuleBase, activation: Activation, root: DIKey, roots: DIKey*): PlannerInput = PlannerInput(bindings, Roots(root, roots*), activation, DefaultPrivacy) + implicit def plannerInputOrdering: Ordering[PlannerInput] = Ordering.by(_.hashCode()) } diff --git a/distage/distage-core-api/src/main/scala/izumi/distage/model/plan/Plan.scala b/distage/distage-core-api/src/main/scala/izumi/distage/model/plan/Plan.scala index 17958b71d0..c350074e7f 100644 --- a/distage/distage-core-api/src/main/scala/izumi/distage/model/plan/Plan.scala +++ b/distage/distage-core-api/src/main/scala/izumi/distage/model/plan/Plan.scala @@ -226,4 +226,6 @@ object Plan { } } + implicit def planOrdering: Ordering[Plan] = Ordering.by(_.input) + } diff --git a/distage/distage-testkit-core/src/main/scala/izumi/distage/testkit/model/TestGroup.scala b/distage/distage-testkit-core/src/main/scala/izumi/distage/testkit/model/TestGroup.scala index 2a6dd62997..a37ad07a87 100644 --- a/distage/distage-testkit-core/src/main/scala/izumi/distage/testkit/model/TestGroup.scala +++ b/distage/distage-testkit-core/src/main/scala/izumi/distage/testkit/model/TestGroup.scala @@ -5,6 +5,7 @@ import izumi.distage.model.plan.Plan import izumi.distage.model.reflection.DIKey import izumi.distage.testkit.runner.impl.services.Timed import izumi.fundamentals.collections.nonempty.NEList +import scala.math.Ordering final case class PreparedTest[F[_]]( test: DistageTest[F], @@ -12,6 +13,13 @@ final case class PreparedTest[F[_]]( roots: Set[DIKey], ) +object PreparedTest { + implicit def orderedPreparedTest[F[_]]: Ordering[PreparedTest[F[_]]] = + Ordering.by { case PreparedTest(test, _, _) => + (test.testMeta.pos.file, test.testMeta.pos.line) + } +} + final case class FailedTest[F[_]]( test: DistageTest[F], timedPlan: Timed[NEList[DIError]], diff --git a/distage/distage-testkit-core/src/main/scala/izumi/distage/testkit/model/TestTree.scala b/distage/distage-testkit-core/src/main/scala/izumi/distage/testkit/model/TestTree.scala index 9abae91bed..e61f1e41c0 100644 --- a/distage/distage-testkit-core/src/main/scala/izumi/distage/testkit/model/TestTree.scala +++ b/distage/distage-testkit-core/src/main/scala/izumi/distage/testkit/model/TestTree.scala @@ -80,3 +80,8 @@ final case class TestTree[F[_]]( } } } + +object TestTree { + implicit def testTreeOrdering[F[_]]: Ordering[TestTree[F[_]]] = Ordering.by(_.levelPlan) +} + diff --git a/distage/distage-testkit-core/src/main/scala/izumi/distage/testkit/runner/impl/DistageTestRunner.scala b/distage/distage-testkit-core/src/main/scala/izumi/distage/testkit/runner/impl/DistageTestRunner.scala index 6d51bbdf52..25fe9fe778 100644 --- a/distage/distage-testkit-core/src/main/scala/izumi/distage/testkit/runner/impl/DistageTestRunner.scala +++ b/distage/distage-testkit-core/src/main/scala/izumi/distage/testkit/runner/impl/DistageTestRunner.scala @@ -17,6 +17,13 @@ import scala.concurrent.duration.FiniteDuration object DistageTestRunner { case class SuiteData(id: SuiteId, meta: SuiteMeta, suiteParallelism: Parallelism) + + object SuiteData { + implicit def suiteDataOrdering: Ordering[SuiteData] = Ordering.by { + case SuiteData(id, meta, suiteParallelism) => + (id.suiteId, meta.suiteName, meta.suiteClassName, suiteParallelism.toString()) + } + } } class DistageTestRunner[F[_]: TagK, G[_]]( diff --git a/distage/distage-testkit-core/src/main/scala/izumi/distage/testkit/runner/impl/TestPlanner.scala b/distage/distage-testkit-core/src/main/scala/izumi/distage/testkit/runner/impl/TestPlanner.scala index 2060f4e326..11b01e9cae 100644 --- a/distage/distage-testkit-core/src/main/scala/izumi/distage/testkit/runner/impl/TestPlanner.scala +++ b/distage/distage-testkit-core/src/main/scala/izumi/distage/testkit/runner/impl/TestPlanner.scala @@ -63,6 +63,11 @@ object TestPlanner { highestDebugOutputInTests: Boolean, ) + object PreparedTestEnv { + implicit def preparedTestEnvOrdering: Ordering[PreparedTestEnv] = + Ordering.by(_.runtimePlan) + } + sealed trait PlanningFailure object PlanningFailure { final case class Exception(throwable: Throwable) extends PlanningFailure diff --git a/distage/distage-testkit-core/src/main/scala/izumi/distage/testkit/runner/impl/TestTreeRunner.scala b/distage/distage-testkit-core/src/main/scala/izumi/distage/testkit/runner/impl/TestTreeRunner.scala index 09f9186386..fdb6887411 100644 --- a/distage/distage-testkit-core/src/main/scala/izumi/distage/testkit/runner/impl/TestTreeRunner.scala +++ b/distage/distage-testkit-core/src/main/scala/izumi/distage/testkit/runner/impl/TestTreeRunner.scala @@ -82,6 +82,8 @@ object TestTreeRunner { // note: scheduling here is custom also and tests may automatically run in parallel for any non-trivial monad // we assume that individual tests within a suite can't have different values of `parallelSuites` // (because of structure & that difference even if happens wouldn't be actionable at the level of suites anyway) + implicit def testsBySuiteOrdering[A]: Ordering[(DistageTestRunner.SuiteData, A)] = Ordering.by(_._1) + parTraverse(testsBySuite)(_._1.suiteParallelism) { case (suiteData, preparedTests) => F.bracket( diff --git a/distage/distage-testkit-core/src/main/scala/izumi/distage/testkit/runner/impl/services/ExtParTraverse.scala b/distage/distage-testkit-core/src/main/scala/izumi/distage/testkit/runner/impl/services/ExtParTraverse.scala index 15c47bbd21..32baa9ba1b 100644 --- a/distage/distage-testkit-core/src/main/scala/izumi/distage/testkit/runner/impl/services/ExtParTraverse.scala +++ b/distage/distage-testkit-core/src/main/scala/izumi/distage/testkit/runner/impl/services/ExtParTraverse.scala @@ -5,7 +5,7 @@ import izumi.functional.quasi.{QuasiAsync, QuasiIO} import izumi.functional.quasi.QuasiIO.syntax.* trait ExtParTraverse[F[_]] { - def apply[A, B]( + def apply[A: Ordering, B]( l: Iterable[A] )(getParallelismGroup: A => Parallelism )(f: A => F[B] @@ -18,7 +18,7 @@ object ExtParTraverse { F: QuasiIO[F], P: QuasiAsync[F], ) extends ExtParTraverse[F] { - def apply[A, B]( + def apply[A: Ordering, B]( l: Iterable[A] )(getParallelismGroup: A => Parallelism )(f: A => F[B] @@ -31,7 +31,7 @@ object ExtParTraverse { F.traverse(sorted) { case (Parallelism.Fixed(n), l) if l.size > 1 => P.parTraverseN(n)(l)(f) case (Parallelism.Unlimited, l) if l.size > 1 => P.parTraverse(l)(f) - case (_, l) => F.traverse(l)(f) + case (_, l) => F.traverse(l.toSeq.sorted)(f) }.map(_.flatten) } }