Skip to content

Commit

Permalink
add an order to apply on sequential
Browse files Browse the repository at this point in the history
  • Loading branch information
coreyoconnor committed Nov 26, 2024
1 parent 2a7ff5d commit 4e337ee
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Original file line number Diff line number Diff line change
Expand Up @@ -226,4 +226,6 @@ object Plan {
}
}

implicit def planOrdering: Ordering[Plan] = Ordering.by(_.input)

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,21 @@ 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],
timedPlan: Timed[Plan],
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]],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,8 @@ final case class TestTree[F[_]](
}
}
}

object TestTree {
implicit def testTreeOrdering[F[_]]: Ordering[TestTree[F[_]]] = Ordering.by(_.levelPlan)
}

Original file line number Diff line number Diff line change
Expand Up @@ -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[_]](
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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]
Expand All @@ -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)
}
}
Expand Down

0 comments on commit 4e337ee

Please sign in to comment.