Skip to content

Instantly share code, notes, and snippets.

@xuwei-k
Created May 3, 2024 01:03
Show Gist options
  • Save xuwei-k/3dc36ee2719a3a2e5c455937a0eafa8f to your computer and use it in GitHub Desktop.
Save xuwei-k/3dc36ee2719a3a2e5c455937a0eafa8f to your computer and use it in GitHub Desktop.
-Test / javaOptions += "-Dtest-database-name=sample"
+concurrentRestrictions := {
+ val par = parallelExecution.value
+ val max = EvaluateTask.SystemProcessors
+ List(
+ Tags.limitAll(if (par) max else 1),
+ Tags.limit(Tags.ForkedTestGroup, 4), // ここ増やした
+ Tags.exclusiveGroup(Tags.Clean)
+ )
+}
+
+Test / testGrouping := {
+ val groupCount = 4
+ def groupByHash(tests: Seq[TestDefinition]): Seq[Tests.Group] =
+ tests
+ .groupBy(x =>
+ // overflow避けるために一度Longにしている
+ scala.util.hashing.MurmurHash3
+ .stringHash(x.name)
+ .toLong
+ .abs
+ .toInt % groupCount
+ )
+ .map { case (hash, tests) =>
+ println((hash, tests.size))
+ val options = ForkOptions().withRunJVMOptions(
+ (Test / javaOptions).value.toVector ++ Vector(
+ s"-Dtest-database-name=${hash}"
+ )
+ )
+ new Tests.Group(hash.toString, tests, Tests.SubProcess(options))
+ }
+ .toSeq
+ groupByHash((Test / definedTests).value)
+}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment