-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added Performance Metrics for Android (#1292)
* feat: Added Performance Metrics for Android * Add tests * Add tests
- Loading branch information
1 parent
ab55fbc
commit 68d52d8
Showing
10 changed files
with
252 additions
and
20 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
34 changes: 34 additions & 0 deletions
34
test_runner/src/main/kotlin/ftl/reports/api/PerformanceMetrics.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,34 @@ | ||
package ftl.reports.api | ||
|
||
import com.google.api.services.testing.model.TestExecution | ||
import com.google.api.services.toolresults.model.PerfMetricsSummary | ||
import ftl.android.AndroidCatalog | ||
import ftl.gc.GcStorage | ||
import ftl.gc.GcToolResults | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.async | ||
import kotlinx.coroutines.awaitAll | ||
import kotlinx.coroutines.runBlocking | ||
|
||
internal fun List<Pair<TestExecution, String>>.getAndUploadPerformanceMetrics( | ||
resultBucket: String | ||
) = runBlocking { | ||
filterAndroidPhysicalDevicesRuns() | ||
.map { (testExecution, gcsStoragePath) -> | ||
async(Dispatchers.IO) { | ||
testExecution.getPerformanceMetric().upload(resultBucket = resultBucket, resultDir = gcsStoragePath) | ||
} | ||
} | ||
.awaitAll() | ||
} | ||
|
||
private fun List<Pair<TestExecution, String>>.filterAndroidPhysicalDevicesRuns() = filterNot { (testExecution, _) -> | ||
AndroidCatalog.isVirtualDevice(testExecution.environment.androidDevice, testExecution.projectId) | ||
} | ||
|
||
private fun TestExecution.getPerformanceMetric() = GcToolResults.getPerformanceMetric(toolResultsStep) | ||
|
||
private fun PerfMetricsSummary.upload( | ||
resultBucket: String, | ||
resultDir: String | ||
) = GcStorage.uploadPerformanceMetrics(this, resultBucket, resultDir) |
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
70 changes: 70 additions & 0 deletions
70
test_runner/src/test/kotlin/ftl/reports/api/PerformanceMetricsTest.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,70 @@ | ||
package ftl.reports.api | ||
|
||
import com.google.api.services.testing.model.AndroidDevice | ||
import com.google.api.services.testing.model.TestExecution | ||
import com.google.api.services.testing.model.ToolResultsStep | ||
import com.google.common.truth.Truth.assertThat | ||
import ftl.android.AndroidCatalog | ||
import ftl.gc.GcStorage | ||
import ftl.gc.GcToolResults | ||
import ftl.test.util.FlankTestRunner | ||
import io.mockk.every | ||
import io.mockk.mockk | ||
import io.mockk.mockkObject | ||
import io.mockk.unmockkAll | ||
import io.mockk.verify | ||
import org.junit.After | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
@RunWith(FlankTestRunner::class) | ||
class PerformanceMetricsTest { | ||
|
||
@After | ||
fun tearDown() = unmockkAll() | ||
|
||
@Test | ||
fun `should not get and upload performance metrics for virtual devices`() { | ||
mockkObject(AndroidCatalog) { | ||
every { AndroidCatalog.isVirtualDevice(any<AndroidDevice>(), any()) } returns true | ||
|
||
assertThat(testExecutions.map { it to "path" }.getAndUploadPerformanceMetrics("b8ce")).isEmpty() | ||
} | ||
} | ||
|
||
@Test | ||
fun `should get and upload performance metrics for physical devices`() { | ||
val expectedBucket = "bucket" | ||
val expectedPath = "path" | ||
|
||
mockkObject(AndroidCatalog) { | ||
every { AndroidCatalog.isVirtualDevice(any<AndroidDevice>(), any()) } returns false | ||
val performanceMetrics = testExecutions.map { | ||
GcToolResults.getPerformanceMetric(it.toolResultsStep) | ||
} | ||
|
||
mockkObject(GcStorage) { | ||
testExecutions.map { it to expectedPath }.getAndUploadPerformanceMetrics(expectedBucket) | ||
performanceMetrics.forEach { | ||
verify { GcStorage.uploadPerformanceMetrics(it, expectedBucket, expectedPath) } | ||
} | ||
} | ||
} | ||
} | ||
|
||
private val testExecutions = (1..5).map { | ||
mockk<TestExecution> { | ||
every { projectId } returns "test" | ||
every { toolResultsStep } returns toolResultsStep(it) | ||
every { environment } returns mockk { | ||
every { androidDevice } returns AndroidDevice().setAndroidModelId(it.toString()) | ||
} | ||
} | ||
} | ||
|
||
private fun toolResultsStep(id: Int) = ToolResultsStep() | ||
.setStepId(id.toString()) | ||
.setExecutionId(id.toString()) | ||
.setHistoryId(id.toString()) | ||
.setProjectId(id.toString()) | ||
} |
Oops, something went wrong.