@@ -2,9 +2,7 @@ package sbttestshards
2
2
3
3
import sbt .*
4
4
import sbt .Keys .*
5
- import sbttestshards .parsers .JUnitReportParser
6
-
7
- import java .nio .file .Paths
5
+ import sbttestshards .parsers .FullTestReport
8
6
9
7
object TestShardsPlugin extends AutoPlugin {
10
8
@@ -20,11 +18,6 @@ object TestShardsPlugin extends AutoPlugin {
20
18
21
19
override def trigger = allRequirements
22
20
23
- def stringConfig (key : String , default : String ): String = {
24
- val propertyKey = key.replace('_' , '.' ).toLowerCase
25
- sys.props.get(propertyKey).orElse(sys.env.get(key)).getOrElse(default)
26
- }
27
-
28
21
override lazy val projectSettings : Seq [Def .Setting [? ]] =
29
22
Seq (
30
23
testShard := stringConfig(" TEST_SHARD" , " 0" ).toInt,
@@ -50,24 +43,19 @@ object TestShardsPlugin extends AutoPlugin {
50
43
val shardContext = ShardContext (testShard.value, testShardCount.value, sLog.value)
51
44
val logger = shardContext.logger
52
45
val algorithm = shardingAlgorithm.value
53
-
54
- // TODO:: Make path customizable
55
- val fullTestReport = JUnitReportParser .parseDirectoriesRecursively(
56
- Seq (Paths .get(s " test-reports/main/resources/test-reports " , moduleName.value))
57
- )
58
-
46
+ val priorReport = algorithm.priorReport.getOrElse(FullTestReport .empty)
59
47
val sbtSuiteNames = (Test / definedTestNames).value.toSet
60
- val missingSuiteNames = sbtSuiteNames diff fullTestReport .testReports.map(_.name).toSet
48
+ val missingSuiteNames = sbtSuiteNames diff priorReport .testReports.map(_.name).toSet
61
49
62
- val results = fullTestReport .testReports.map { suiteReport =>
50
+ val results = priorReport .testReports.map { suiteReport =>
63
51
val shardResult = algorithm.check(suiteReport.name, shardContext)
64
52
65
53
shardResult.testShard -> suiteReport
66
54
}.collect { case (Some (shard), report) => shard -> report }
67
55
.groupBy(_._1)
68
56
69
57
results.toSeq.sortBy(_._1).foreach { case (k, v) =>
70
- val totalTime = v.map(_._2.timeTaken).sum
58
+ val totalTime = BigDecimal ( v.map(_._2.timeTaken).sum).setScale( 3 , BigDecimal . RoundingMode . HALF_UP )
71
59
72
60
logger.info(s " [ ${moduleName.value}] Shard $k expected to take $totalTime s " )
73
61
@@ -76,7 +64,7 @@ object TestShardsPlugin extends AutoPlugin {
76
64
}
77
65
}
78
66
79
- if (missingSuiteNames.nonEmpty) {
67
+ if (missingSuiteNames.nonEmpty) {
80
68
logger.warn(s " Detected ${missingSuiteNames.size} suites that don't have a test report " )
81
69
82
70
missingSuiteNames.foreach { s =>
@@ -86,4 +74,9 @@ object TestShardsPlugin extends AutoPlugin {
86
74
}
87
75
)
88
76
77
+ private def stringConfig (key : String , default : String ): String = {
78
+ val propertyKey = key.replace('_' , '.' ).toLowerCase
79
+ sys.props.get(propertyKey).orElse(sys.env.get(key)).getOrElse(default)
80
+ }
81
+
89
82
}
0 commit comments