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

split test groups to speed up integration tests #1274

Open
wants to merge 1 commit into
base: b2.5
Choose a base branch
from
Open
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
28 changes: 24 additions & 4 deletions project/Testing.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,34 @@ object Testing {
}.toMap
}

private def splitGroupsBiggerThanThreshold(
groupName: String,
groupTests: Iterable[TestDefinition]): TraversableOnce[(String, Iterable[TestDefinition])] = {
val groupSize = sys.env.get("TEST_MAX_GROUP_SIZE").map(_.toInt).getOrElse(MaxGroupSize)
if (groupTests.size > groupSize) {
groupTests.sliding(groupSize, groupSize)
.zipWithIndex
.map { case (ts, index) => (s"${groupName}_splitted_$index", ts) }
} else {
Seq((groupName, groupTests))
}
}

def makeTestGroups(testsWithFixtures: Map[TestDefinition, Seq[String]]): Seq[Group] = {
val (separateJVMTests, groupedTests) = testsWithFixtures
.partition { case (_, fixtures) => fixtures.contains("SeparateJVM") }

val testsByGroupName = groupedTests.groupBy(_._2).map { case (fixtures, tests) => (fixtures.mkString("-"), tests.keys) } ++
separateJVMTests.zipWithIndex.map { case ((test, fixtures), i) => ((fixtures ++ i.toString).mkString("-"), Seq(test)) }
val testsByName = groupedTests.groupBy(_._2)
.map { case (fixtures, tests) => (fixtures.mkString("-"), tests.keys) }
.flatMap { case (name, tests) => splitGroupsBiggerThanThreshold(name, tests) }

val separateJVMTestsByName = separateJVMTests.zipWithIndex
.map { case ((test, fixtures), i) => ((fixtures ++ i.toString).mkString("-"), Seq(test)) }

val allTestsByName = testsByName ++ separateJVMTestsByName
println(s"All existing tests divided into ${allTestsByName.size} groups:")

println(s"All existing tests divided into ${testsByGroupName.size} groups:")
testsByGroupName.toSeq
allTestsByName.toSeq
.sortBy(-_._2.size) // biggest groups are executed first
.zipWithIndex
.map { case ((groupName, tests), i) =>
Expand Down Expand Up @@ -56,6 +75,7 @@ object Testing {
}

val MaxParallel = 10
val MaxGroupSize = 20

lazy val parallelTasks: Int = {
val parallelTasks = sys.env.get("TEST_PARALLEL_TASKS").map(_.toInt).getOrElse {
Expand Down