-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* #707 Refactor Shared object by splitting it into smaller functions * #707 Updated Release notes * #707 Refactor Shared object by splitting it into smaller functions * #707 Refactor Shared object by splitting it into smaller functions * #707 Refactor Shared object by splitting it into smaller functions * #707 fixed PR comments * #707 fixed PR comments * #707 Refactor Shared object by splitting it into smaller functions * #707 Refactor Shared object by splitting it into smaller functions * #707 Refactor Shared object by splitting it into smaller functions * #707 Refactor Shared object by splitting it into smaller functions * #707 Refactor Shared object by splitting it into smaller functions * #707 Refactor Shared object by splitting it into smaller functions * #707 Refactor Shared object by splitting it into smaller functions
- Loading branch information
1 parent
e95ac5c
commit c5e7608
Showing
14 changed files
with
408 additions
and
245 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package ftl.shard | ||
|
||
import ftl.util.FlankTestMethod | ||
import kotlin.math.roundToInt | ||
|
||
fun printCacheInfo(testsToRun: List<FlankTestMethod>, previousMethodDurations: Map<String, Double>) { | ||
val allTestCount = testsToRun.size | ||
val cacheHit = cacheHit(allTestCount, calculateCacheMiss(testsToRun, previousMethodDurations)) | ||
val cachePercent = cachePercent(allTestCount, cacheHit) | ||
println() | ||
println(" Smart Flank cache hit: ${cachePercent.roundToInt()}% ($cacheHit / $allTestCount)") | ||
} | ||
|
||
private fun cacheHit(allTestCount: Int, cacheMiss: Int) = allTestCount - cacheMiss | ||
|
||
private fun calculateCacheMiss(testsToRun: List<FlankTestMethod>, previousMethodDurations: Map<String, Double>): Int { | ||
return testsToRun.count { !previousMethodDurations.containsKey(it.testName) } | ||
} | ||
|
||
private fun cachePercent(allTestCount: Int, cacheHit: Int): Double = | ||
if (allTestCount == 0) 0.0 else cacheHit.toDouble() / allTestCount * 100.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package ftl.shard | ||
|
||
import ftl.args.IArgs | ||
import ftl.args.IArgs.Companion.AVAILABLE_SHARD_COUNT_RANGE | ||
import ftl.reports.xml.model.JUnitTestResult | ||
import ftl.util.FlankFatalError | ||
import ftl.util.FlankTestMethod | ||
import kotlin.math.ceil | ||
import kotlin.math.min | ||
|
||
private const val SINGLE_SHARD = 1 | ||
private const val NO_LIMIT = -1 | ||
|
||
// take in the XML with timing info then return the shard count based on execution time | ||
fun shardCountByTime( | ||
testsToRun: List<FlankTestMethod>, | ||
oldTestResult: JUnitTestResult, | ||
args: IArgs | ||
): Int = when { | ||
args.shardTime == NO_LIMIT -> NO_LIMIT | ||
args.shardTime < NO_LIMIT || args.shardTime == 0 -> throw FlankFatalError("Invalid shard time ${args.shardTime}") | ||
else -> calculateShardCount(testsToRun, oldTestResult, args) | ||
} | ||
|
||
private fun calculateShardCount( | ||
testsToRun: List<FlankTestMethod>, | ||
oldTestResult: JUnitTestResult, | ||
args: IArgs | ||
): Int = calculateShardCount( | ||
args = args, | ||
testsTotalTime = testTotalTime(testsToRun, createTestMethodDurationMap(oldTestResult, args)), | ||
testsToRunCount = testsToRun.size | ||
) | ||
|
||
private fun testTotalTime(testsToRun: List<FlankTestMethod>, previousMethodDurations: Map<String, Double>): Double = | ||
testsToRun.sumByDouble { flankTestMethod -> getTestMethodTime(flankTestMethod, previousMethodDurations) } | ||
|
||
private fun calculateShardCount( | ||
args: IArgs, | ||
testsTotalTime: Double, | ||
testsToRunCount: Int | ||
): Int = when { | ||
testsTotalTime <= args.shardTime -> SINGLE_SHARD | ||
args.maxTestShards == NO_LIMIT -> min(AVAILABLE_SHARD_COUNT_RANGE.last, testsToRunCount) | ||
else -> shardCount(testsTotalTime, args).also { count -> | ||
if (count <= 0) throw FlankFatalError("Invalid shard count $count") | ||
} | ||
} | ||
|
||
private fun shardCount(testsTotalTime: Double, args: IArgs) = | ||
min(shardsByTime(testsTotalTime, args), args.maxTestShards) | ||
|
||
private fun shardsByTime(testsTotalTime: Double, args: IArgs) = ceil(testsTotalTime / args.shardTime).toInt() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package ftl.shard | ||
|
||
import ftl.util.FlankTestMethod | ||
|
||
data class TestMethod( | ||
val name: String, | ||
val time: Double | ||
) | ||
|
||
fun createTestCases(testsToRun: List<FlankTestMethod>, previousMethodDurations: Map<String, Double>): List<TestMethod> { | ||
return testsToRun.map { TestMethod(it.testName, getTestMethodTime(it, previousMethodDurations)) } | ||
} |
35 changes: 35 additions & 0 deletions
35
test_runner/src/main/kotlin/ftl/shard/TestMethodDuration.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package ftl.shard | ||
|
||
import ftl.args.AndroidArgs | ||
import ftl.args.IArgs | ||
import ftl.reports.xml.model.JUnitTestCase | ||
import ftl.reports.xml.model.JUnitTestResult | ||
|
||
fun createTestMethodDurationMap(junitResult: JUnitTestResult, args: IArgs): Map<String, Double> { | ||
val junitMap = mutableMapOf<String, Double>() | ||
|
||
// Create a map with information from previous junit run | ||
|
||
junitResult.testsuites?.forEach { testsuite -> | ||
testsuite.testcases?.forEach { testcase -> | ||
if (!testcase.empty() && testcase.time != null) { | ||
val key = if (args is AndroidArgs) testcase.androidKey() else testcase.iosKey() | ||
val time = testcase.time.toDouble() | ||
if (time >= 0) junitMap[key] = time | ||
} | ||
} | ||
} | ||
|
||
return junitMap | ||
} | ||
|
||
private fun JUnitTestCase.androidKey(): String { | ||
return "class $classname#$name" | ||
} | ||
|
||
private fun JUnitTestCase.iosKey(): String { | ||
// FTL iOS XML appends `()` to each test name. ex: `testBasicSelection()` | ||
// xctestrun file requires classname/name with no `()` | ||
val testName = name?.substringBefore('(') | ||
return "$classname/$testName" | ||
} |
Oops, something went wrong.