forked from MarathonLabs/marathon
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
648d5bc
commit 1c5b089
Showing
8 changed files
with
110 additions
and
89 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
marathon-gradle-plugin/src/main/kotlin/com/malinskiy/marathon/MarathonBuildService.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,46 @@ | ||
package com.malinskiy.marathon | ||
|
||
import com.malinskiy.marathon.execution.ComponentInfo | ||
import com.malinskiy.marathon.worker.WorkerContext | ||
import com.malinskiy.marathon.worker.WorkerHandler | ||
import org.gradle.api.file.DirectoryProperty | ||
import org.gradle.api.provider.Property | ||
import org.gradle.api.services.BuildService | ||
import org.gradle.api.services.BuildServiceParameters | ||
|
||
abstract class MarathonBuildService : BuildService<MarathonBuildService.Params>, WorkerHandler { | ||
private val lazyWorkerContext = lazy { | ||
val configuration = createCommonConfiguration( | ||
parameters.marathonConfig.get(), | ||
parameters.adbPath.get().asFile, | ||
parameters.outputDir.get().asFile | ||
) | ||
WorkerContext(configuration) | ||
} | ||
|
||
override fun scheduleTests(componentInfo: ComponentInfo) { | ||
lazyWorkerContext.value.scheduleTests(componentInfo) | ||
} | ||
|
||
override fun await() { | ||
if (lazyWorkerContext.isInitialized()) { | ||
lazyWorkerContext.value.await() | ||
} | ||
} | ||
|
||
override fun close() { | ||
if (lazyWorkerContext.isInitialized()) { | ||
lazyWorkerContext.value.close() | ||
} | ||
} | ||
|
||
interface Params : BuildServiceParameters { | ||
val adbPath: DirectoryProperty | ||
val outputDir: DirectoryProperty | ||
val marathonConfig: Property<MarathonExtension> | ||
} | ||
|
||
companion object { | ||
const val NAME = "marathon" | ||
} | ||
} |
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
10 changes: 8 additions & 2 deletions
10
marathon-gradle-plugin/src/main/kotlin/com/malinskiy/marathon/MarathonWorkerRunTask.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,12 +1,18 @@ | ||
package com.malinskiy.marathon | ||
|
||
import com.malinskiy.marathon.worker.MarathonWorker | ||
import org.gradle.api.DefaultTask | ||
import org.gradle.api.provider.Property | ||
import org.gradle.api.services.ServiceReference | ||
import org.gradle.api.tasks.TaskAction | ||
import org.gradle.work.DisableCachingByDefault | ||
|
||
@DisableCachingByDefault | ||
abstract class MarathonWorkerRunTask : DefaultTask() { | ||
@get:ServiceReference(MarathonBuildService.NAME) | ||
abstract val buildService: Property<MarathonBuildService> | ||
|
||
@TaskAction | ||
fun run() { | ||
MarathonWorker.await() | ||
buildService.get().await() | ||
} | ||
} |
24 changes: 0 additions & 24 deletions
24
marathon-gradle-plugin/src/main/kotlin/com/malinskiy/marathon/worker/MarathonWorker.kt
This file was deleted.
Oops, something went wrong.
59 changes: 31 additions & 28 deletions
59
marathon-gradle-plugin/src/main/kotlin/com/malinskiy/marathon/worker/WorkerContext.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
5 changes: 1 addition & 4 deletions
5
marathon-gradle-plugin/src/main/kotlin/com/malinskiy/marathon/worker/WorkerHandler.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,11 +1,8 @@ | ||
package com.malinskiy.marathon.worker | ||
|
||
import com.malinskiy.marathon.execution.ComponentInfo | ||
import com.malinskiy.marathon.execution.Configuration | ||
|
||
interface WorkerHandler { | ||
fun initialize(configuration: Configuration) | ||
fun ensureStarted() | ||
interface WorkerHandler : AutoCloseable { | ||
fun scheduleTests(componentInfo: ComponentInfo) | ||
fun await() | ||
} |
33 changes: 12 additions & 21 deletions
33
marathon-gradle-plugin/src/main/kotlin/com/malinskiy/marathon/worker/WorkerRunnable.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,47 +1,38 @@ | ||
package com.malinskiy.marathon.worker | ||
|
||
import com.malinskiy.marathon.Marathon | ||
import com.malinskiy.marathon.di.marathonStartKoin | ||
import com.malinskiy.marathon.execution.ComponentInfo | ||
import com.malinskiy.marathon.execution.Configuration | ||
import com.malinskiy.marathon.log.MarathonLogging | ||
import kotlinx.coroutines.channels.Channel | ||
import kotlinx.coroutines.runBlocking | ||
import org.gradle.api.GradleException | ||
|
||
class WorkerRunnable( | ||
private val componentsChannel: Channel<ComponentInfo>, | ||
private val configuration: Configuration | ||
internal class WorkerRunnable( | ||
private val marathon: Marathon, | ||
private val componentsChannel: Channel<ComponentInfo> | ||
) : Runnable { | ||
|
||
private val log = MarathonLogging.logger {} | ||
|
||
override fun run() = runBlocking { | ||
log.debug("Starting Marathon worker") | ||
marathon.start() | ||
|
||
val application = marathonStartKoin(configuration) | ||
try { | ||
val marathon = application.koin.get<Marathon>() | ||
marathon.start() | ||
|
||
for (component in componentsChannel) { | ||
log.debug("Scheduling tests for $component") | ||
marathon.scheduleTests(component) | ||
} | ||
|
||
log.debug("Waiting for completion") | ||
stopAndWaitForCompletion(marathon) | ||
} finally { | ||
application.close() | ||
for (component in componentsChannel) { | ||
log.debug("Scheduling tests for $component") | ||
marathon.scheduleTests(component) | ||
} | ||
|
||
log.debug("Waiting for completion") | ||
stopAndWaitForCompletion(marathon) | ||
} | ||
|
||
private suspend fun stopAndWaitForCompletion(marathon: Marathon) { | ||
val success = marathon.stopAndWaitForCompletion() | ||
|
||
val shouldReportFailure = !configuration.ignoreFailures | ||
val shouldReportFailure = !marathon.configuration.ignoreFailures | ||
if (!success && shouldReportFailure) { | ||
throw GradleException("Tests failed! See ${configuration.outputDir}/html/index.html") | ||
throw GradleException("Tests failed! See ${marathon.configuration.outputDir}/html/index.html") | ||
} | ||
} | ||
} |