-
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.
Fixes #1755 ## Test Plan > How do we know the code works? - Code is refactored according to description provided by #1755 - It takes into account work done on: #1941 and attempts to be as close as possible for consistency. ## Checklist - [x] Unit tested - [x] Integration tests updated
- Loading branch information
Showing
12 changed files
with
271 additions
and
159 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
16 changes: 16 additions & 0 deletions
16
test_runner/src/main/kotlin/ftl/adapter/GoogleTestMatrixIos.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,16 @@ | ||
package ftl.adapter | ||
|
||
import ftl.adapter.google.toApiModel | ||
import ftl.api.TestMatrix | ||
import ftl.api.TestMatrixIos | ||
import ftl.client.google.run.ios.executeIosTests | ||
import kotlinx.coroutines.runBlocking | ||
import com.google.testing.model.TestMatrix as GoogleTestMatrix | ||
|
||
object GoogleTestMatrixIos : | ||
TestMatrixIos.Execute, | ||
(TestMatrixIos.Config, List<TestMatrixIos.Type>) -> List<TestMatrix.Data> by { config, types -> | ||
runBlocking { | ||
executeIosTests(config, types).map(GoogleTestMatrix::toApiModel) | ||
} | ||
} |
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,45 @@ | ||
package ftl.api | ||
|
||
import ftl.adapter.GoogleTestMatrixIos | ||
import ftl.config.Device | ||
|
||
val executeTestMatrixIos: TestMatrixIos.Execute get() = GoogleTestMatrixIos | ||
|
||
object TestMatrixIos { | ||
|
||
data class Config( | ||
// args | ||
val clientDetails: Map<String, String>?, | ||
val networkProfile: String?, | ||
val directoriesToPull: List<String>, | ||
val testTimeout: String, | ||
val recordVideo: Boolean, | ||
val flakyTestAttempts: Int, | ||
val failFast: Boolean, | ||
val project: String, | ||
val resultsHistoryName: String?, | ||
|
||
// build | ||
val devices: List<Device>, | ||
val otherFiles: Map<String, String>, | ||
val additionalIpasGcsPaths: List<String>, | ||
) | ||
|
||
sealed class Type(open val matrixGcsPath: String) { | ||
data class XcTest( | ||
val xcTestGcsPath: String, | ||
val xcTestRunFileGcsPath: String, | ||
val xcodeVersion: String, | ||
val testSpecialEntitlements: Boolean, | ||
override val matrixGcsPath: String, | ||
) : Type(matrixGcsPath) | ||
|
||
data class GameLoop( | ||
val appGcsPath: String, | ||
val scenarios: List<Int>, | ||
override val matrixGcsPath: String, | ||
) : Type(matrixGcsPath) | ||
} | ||
|
||
interface Execute : (Config, List<Type>) -> List<TestMatrix.Data> | ||
} |
4 changes: 2 additions & 2 deletions
4
...ner/src/main/kotlin/ftl/gc/GcIosMatrix.kt → .../ftl/client/google/run/ios/GcIosDevice.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
93 changes: 93 additions & 0 deletions
93
test_runner/src/main/kotlin/ftl/client/google/run/ios/GcIosTestMatrix.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,93 @@ | ||
package ftl.client.google.run.ios | ||
|
||
import com.google.testing.Testing | ||
import com.google.testing.model.ClientInfo | ||
import com.google.testing.model.EnvironmentMatrix | ||
import com.google.testing.model.GoogleCloudStorage | ||
import com.google.testing.model.IosTestSetup | ||
import com.google.testing.model.ResultStorage | ||
import com.google.testing.model.TestMatrix | ||
import com.google.testing.model.TestSpecification | ||
import com.google.testing.model.ToolResultsHistory | ||
import ftl.api.TestMatrixIos | ||
import ftl.client.google.GcTesting | ||
import ftl.client.google.run.mapGcsPathsToFileReference | ||
import ftl.client.google.run.mapToIosDeviceFiles | ||
import ftl.client.google.run.toClientInfoDetailList | ||
import ftl.client.google.run.toIosDeviceFile | ||
import ftl.http.executeWithRetry | ||
import ftl.run.exception.FlankGeneralError | ||
import ftl.util.timeoutToSeconds | ||
import kotlinx.coroutines.Deferred | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.async | ||
import kotlinx.coroutines.awaitAll | ||
import kotlinx.coroutines.coroutineScope | ||
|
||
suspend fun executeIosTests( | ||
config: TestMatrixIos.Config, | ||
testMatrixTypes: List<TestMatrixIos.Type>, | ||
): List<TestMatrix> = testMatrixTypes | ||
.foldIndexed(emptyList<Deferred<TestMatrix>>()) { _, testMatrices, testMatrixType -> | ||
testMatrices + executeIosTestMatrixAsync(testMatrixType, config) | ||
}.awaitAll() | ||
|
||
private suspend fun executeIosTestMatrixAsync( | ||
type: TestMatrixIos.Type, | ||
config: TestMatrixIos.Config | ||
): Deferred<TestMatrix> = coroutineScope { | ||
async(Dispatchers.IO) { | ||
createIosTestMatrix(type, config).executeWithRetry() | ||
} | ||
} | ||
|
||
private fun createIosTestMatrix( | ||
testMatrixType: TestMatrixIos.Type, | ||
config: TestMatrixIos.Config, | ||
): Testing.Projects.TestMatrices.Create { | ||
|
||
val testMatrix = TestMatrix() | ||
.setClientInfo(config.clientInfo) | ||
.setTestSpecification(getIosTestSpecification(testMatrixType, config)) | ||
.setEnvironmentMatrix(config.environmentMatrix) | ||
.setResultStorage(resultsStorage(config, testMatrixType)) | ||
.setFlakyTestAttempts(config.flakyTestAttempts) | ||
.setFailFast(config.failFast) | ||
|
||
return runCatching { | ||
GcTesting.get.projects().testMatrices().create(config.project, testMatrix) | ||
}.getOrElse { throw FlankGeneralError(it) } | ||
} | ||
|
||
private fun resultsStorage(config: TestMatrixIos.Config, type: TestMatrixIos.Type): ResultStorage { | ||
return ResultStorage().setGoogleCloudStorage( | ||
GoogleCloudStorage().setGcsPath(type.matrixGcsPath) | ||
).setToolResultsHistory( | ||
ToolResultsHistory().setHistoryId(config.resultsHistoryName).setProjectId(config.project) | ||
) | ||
} | ||
|
||
private val TestMatrixIos.Config.environmentMatrix | ||
get() = EnvironmentMatrix().setIosDeviceList(GcIosDevice.build(devices)) | ||
|
||
private fun getIosTestSpecification( | ||
testMatrixType: TestMatrixIos.Type, | ||
config: TestMatrixIos.Config | ||
): TestSpecification = TestSpecification() | ||
.setDisableVideoRecording(!config.recordVideo) | ||
.setTestTimeout("${timeoutToSeconds(config.testTimeout)}s") | ||
.setIosTestSetup(getIosTestSetup(config)) | ||
.setupIosTest(testMatrixType) | ||
|
||
private fun getIosTestSetup( | ||
config: TestMatrixIos.Config | ||
): IosTestSetup = IosTestSetup() | ||
.setNetworkProfile(config.networkProfile) | ||
.setPushFiles(config.otherFiles.mapToIosDeviceFiles()) | ||
.setAdditionalIpas(config.additionalIpasGcsPaths.mapGcsPathsToFileReference()) | ||
.setPullDirectories(config.directoriesToPull.toIosDeviceFiles()) | ||
|
||
private fun List<String>.toIosDeviceFiles() = map { path -> toIosDeviceFile(path) } | ||
|
||
private val TestMatrixIos.Config.clientInfo | ||
get() = ClientInfo().setName("Flank").setClientInfoDetails(clientDetails?.toClientInfoDetailList()) |
18 changes: 8 additions & 10 deletions
18
...rc/main/kotlin/ftl/gc/ios/SetupIosTest.kt → ...ftl/client/google/run/ios/SetupIosTest.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 |
---|---|---|
@@ -1,28 +1,26 @@ | ||
package ftl.gc.ios | ||
package ftl.client.google.run.ios | ||
|
||
import com.google.testing.model.FileReference | ||
import com.google.testing.model.IosTestLoop | ||
import com.google.testing.model.IosXcTest | ||
import com.google.testing.model.TestSpecification | ||
import ftl.run.model.GameloopTestContext | ||
import ftl.run.model.IosTestContext | ||
import ftl.run.model.XcTestContext | ||
import ftl.api.TestMatrixIos | ||
|
||
fun TestSpecification.setupIosTest(context: IosTestContext) = apply { | ||
when (context) { | ||
is XcTestContext -> iosXcTest = setupXcTest(context) | ||
is GameloopTestContext -> iosTestLoop = setupGameLoopTest(context) | ||
internal fun TestSpecification.setupIosTest(config: TestMatrixIos.Type) = apply { | ||
when (config) { | ||
is TestMatrixIos.Type.XcTest -> iosXcTest = setupXcTest(config) | ||
is TestMatrixIos.Type.GameLoop -> iosTestLoop = setupGameLoopTest(config) | ||
} | ||
} | ||
|
||
private fun setupXcTest(context: XcTestContext) = IosXcTest().apply { | ||
private fun setupXcTest(context: TestMatrixIos.Type.XcTest) = IosXcTest().apply { | ||
testsZip = FileReference().setGcsPath(context.xcTestGcsPath) | ||
xctestrun = FileReference().setGcsPath(context.xcTestRunFileGcsPath) | ||
xcodeVersion = context.xcodeVersion | ||
testSpecialEntitlements = context.testSpecialEntitlements | ||
} | ||
|
||
private fun setupGameLoopTest(context: GameloopTestContext) = IosTestLoop().apply { | ||
private fun setupGameLoopTest(context: TestMatrixIos.Type.GameLoop) = IosTestLoop().apply { | ||
appIpa = FileReference().setGcsPath(context.appGcsPath) | ||
scenarios = context.scenarios | ||
} |
This file was deleted.
Oops, something went wrong.
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
24 changes: 24 additions & 0 deletions
24
test_runner/src/main/kotlin/ftl/run/platform/ios/CreateIosTestConfig.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,24 @@ | ||
package ftl.run.platform.ios | ||
|
||
import ftl.api.TestMatrixIos | ||
import ftl.args.IosArgs | ||
import ftl.client.google.GcToolResults | ||
import ftl.run.platform.android.uploadAdditionalIpas | ||
import ftl.run.platform.android.uploadOtherFiles | ||
|
||
suspend fun createIosTestConfig( | ||
args: IosArgs | ||
): TestMatrixIos.Config = TestMatrixIos.Config( | ||
clientDetails = args.clientDetails, | ||
networkProfile = args.networkProfile, | ||
directoriesToPull = args.directoriesToPull, | ||
testTimeout = args.testTimeout, | ||
recordVideo = args.recordVideo, | ||
flakyTestAttempts = args.flakyTestAttempts, | ||
failFast = args.failFast, | ||
project = args.project, | ||
resultsHistoryName = GcToolResults.createToolResultsHistory(args).historyId, | ||
devices = args.devices, | ||
otherFiles = args.uploadOtherFiles(), | ||
additionalIpasGcsPaths = args.uploadAdditionalIpas(), | ||
) |
Oops, something went wrong.