Skip to content

Commit

Permalink
Merge pull request #37 from craigatk/launch
Browse files Browse the repository at this point in the history
(feature) Improving performance of launch in saving test results
  • Loading branch information
craigatk committed Apr 1, 2020
2 parents 1617df4 + 143e85e commit f3fdbc2
Show file tree
Hide file tree
Showing 12 changed files with 55 additions and 50 deletions.
2 changes: 0 additions & 2 deletions server/server-app/src/main/kotlin/projektor/AppModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package projektor

import com.zaxxer.hikari.HikariDataSource
import io.ktor.util.KtorExperimentalAPI
import kotlinx.coroutines.ObsoleteCoroutinesApi
import org.jooq.DSLContext
import org.koin.dsl.module
import projektor.attachment.AttachmentDatabaseRepository
Expand Down Expand Up @@ -30,7 +29,6 @@ import projektor.testsuite.TestSuiteDatabaseRepository
import projektor.testsuite.TestSuiteRepository
import projektor.testsuite.TestSuiteService

@ObsoleteCoroutinesApi
@KtorExperimentalAPI
fun createAppModule(
dataSource: HikariDataSource,
Expand Down
2 changes: 0 additions & 2 deletions server/server-app/src/main/kotlin/projektor/Application.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import io.ktor.jackson.jackson
import io.ktor.metrics.micrometer.MicrometerMetrics
import io.ktor.routing.routing
import io.ktor.util.KtorExperimentalAPI
import kotlinx.coroutines.ObsoleteCoroutinesApi
import org.koin.Logger.SLF4JLogger
import org.koin.ktor.ext.Koin
import org.koin.ktor.ext.inject
Expand All @@ -41,7 +40,6 @@ import projektor.testrun.TestRunService
import projektor.testrun.attributes.TestRunSystemAttributesService
import projektor.testsuite.TestSuiteService

@ObsoleteCoroutinesApi
@KtorExperimentalAPI
fun Application.main() {
val applicationConfig = environment.config
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package projektor.incomingresults

import kotlinx.coroutines.CoroutineStart
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import kotlinx.coroutines.newFixedThreadPoolContext
import kotlinx.coroutines.*
import org.slf4j.LoggerFactory
import projektor.incomingresults.model.GroupedResults
import projektor.server.api.PublicId
Expand All @@ -18,13 +15,13 @@ class GroupedTestResultsService(
) {
private val logger = LoggerFactory.getLogger(javaClass.canonicalName)

private val asyncSave = newFixedThreadPoolContext(8, "saveGroupedTestResults")
private val coroutineScope = CoroutineScope(Dispatchers.Default)

suspend fun persistTestResultsAsync(groupedResultsXml: String): PublicId {
val publicId = randomPublicId()
testResultsProcessingService.createResultsProcessing(publicId)

GlobalScope.launch(asyncSave, CoroutineStart.DEFAULT) {
coroutineScope.launch {
doPersistTestResults(publicId, groupedResultsXml)
}

Expand All @@ -42,17 +39,14 @@ class GroupedTestResultsService(
return testRunSummary
}

private suspend fun parseGroupedResults(publicId: PublicId, groupedResultsXml: String): GroupedResults {
val groupedResults = try {
private suspend fun parseGroupedResults(publicId: PublicId, groupedResultsXml: String): GroupedResults =
try {
groupedResultsConverter.parseAndConvertGroupedResults(groupedResultsXml)
} catch (e: Exception) {
val errorMessage = "Error parsing test results: ${e.message}"
handleException(publicId, errorMessage, e)
}

return groupedResults
}

private suspend fun persistGroupedResults(publicId: PublicId, groupedResults: GroupedResults): TestRunSummary =
try {
testRunRepository.saveGroupedTestRun(publicId, groupedResults)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,20 @@ import projektor.server.api.TestRunSummary
import projektor.server.api.results.ResultsProcessingStatus
import projektor.testrun.TestRunRepository

@ObsoleteCoroutinesApi
class TestResultsService(
private val testResultsProcessor: TestResultsProcessor,
private val testRunRepository: TestRunRepository,
private val testResultsProcessingService: TestResultsProcessingService
) {
private val logger = LoggerFactory.getLogger(javaClass.canonicalName)

private val asyncSave = newFixedThreadPoolContext(8, "saveTestResults")
private val coroutineScope = CoroutineScope(Dispatchers.Default)

suspend fun persistTestResultsAsync(resultsBlob: String): PublicId {
val publicId = randomPublicId()
testResultsProcessingService.createResultsProcessing(publicId)

GlobalScope.launch(asyncSave, CoroutineStart.DEFAULT) {
coroutineScope.launch {
doPersistTestResults(publicId, resultsBlob)
}

Expand All @@ -41,18 +40,15 @@ class TestResultsService(
return testRunSummary
}

private suspend fun parseTestSuites(publicId: PublicId, resultsBlob: String): List<TestSuite> {
val testSuitesWithTestCases = try {
private suspend fun parseTestSuites(publicId: PublicId, resultsBlob: String): List<TestSuite> =
try {
val parsedTestSuites = testResultsProcessor.parseResultsBlob(resultsBlob)
parsedTestSuites.filter { !it.testCases.isNullOrEmpty() }
} catch (e: Exception) {
val errorMessage = "Error parsing test results: ${e.message}"
handleException(publicId, errorMessage, e)
}

return testSuitesWithTestCases
}

private suspend fun persistTestSuites(publicId: PublicId, testSuites: List<TestSuite>): TestRunSummary =
try {
testRunRepository.saveTestRun(publicId, testSuites)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class ResultsProcessingDatabaseRepository(private val dslContext: DSLContext) :
}

override suspend fun updateResultsProcessingStatus(publicId: PublicId, newStatus: ResultsProcessingStatus): Boolean =
withContext(Dispatchers.IO) {
withContext(Dispatchers.Default) {
dslContext.update(Tables.RESULTS_PROCESSING)
.set(Tables.RESULTS_PROCESSING.STATUS, newStatus.name)
.where(Tables.RESULTS_PROCESSING.PUBLIC_ID.eq(publicId.id))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import io.ktor.config.MapApplicationConfig
import io.ktor.util.KtorExperimentalAPI
import java.math.BigDecimal
import kotlin.test.AfterTest
import kotlinx.coroutines.ObsoleteCoroutinesApi
import org.awaitility.kotlin.await
import org.awaitility.kotlin.until
import org.jooq.DSLContext
Expand Down Expand Up @@ -56,7 +55,6 @@ open class ApplicationTestCase {
protected var metricsEnabled: Boolean? = null
protected var metricsPort: Int = 0

@ObsoleteCoroutinesApi
fun createTestApplication(application: Application) {
val schema = databaseSchema

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import com.zaxxer.hikari.HikariDataSource
import io.ktor.util.KtorExperimentalAPI
import kotlin.test.AfterTest
import kotlin.test.BeforeTest
import kotlinx.coroutines.ObsoleteCoroutinesApi
import org.jooq.DSLContext
import org.jooq.SQLDialect
import org.jooq.impl.DSL
Expand All @@ -29,7 +28,6 @@ open class DatabaseRepositoryTestCase : KoinTest {
lateinit var attachmentDao: TestRunAttachmentDao
lateinit var testRunSystemAttributesDao: TestRunSystemAttributesDao

@ObsoleteCoroutinesApi
@KtorExperimentalAPI
@BeforeTest
fun setup() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ import io.ktor.server.testing.withTestApplication
import io.ktor.util.KtorExperimentalAPI
import java.io.File
import kotlin.test.Test
import kotlinx.coroutines.ObsoleteCoroutinesApi
import projektor.ApplicationTestCase
import projektor.TestSuiteData
import projektor.incomingresults.randomPublicId
import strikt.api.expectThat
import strikt.assertions.isEqualTo

@ObsoleteCoroutinesApi
@KtorExperimentalAPI
@ExperimentalStdlibApi
class AddAttachmentApplicationTest : ApplicationTestCase() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import io.ktor.server.testing.handleRequest
import io.ktor.server.testing.withTestApplication
import io.ktor.util.KtorExperimentalAPI
import kotlin.test.Test
import kotlinx.coroutines.ObsoleteCoroutinesApi
import projektor.ApplicationTestCase
import projektor.server.api.config.ServerConfig
import strikt.api.expectThat
Expand All @@ -15,7 +14,6 @@ import strikt.assertions.isFalse
import strikt.assertions.isNull
import strikt.assertions.isTrue

@ObsoleteCoroutinesApi
@KtorExperimentalAPI
class ConfigApplicationTest : ApplicationTestCase() {
@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package projektor.incomingresults

import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlinx.coroutines.ObsoleteCoroutinesApi
import kotlinx.coroutines.runBlocking
import org.awaitility.kotlin.await
import org.awaitility.kotlin.untilNotNull
Expand All @@ -15,7 +14,6 @@ import strikt.api.expectCatching
import strikt.api.expectThat
import strikt.assertions.*

@ObsoleteCoroutinesApi
class TestResultsServiceTest : DatabaseRepositoryTestCase() {
private lateinit var testResultsService: TestResultsService

Expand Down
41 changes: 41 additions & 0 deletions server/test/load-test/postGroupedResults.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import http from 'k6/http';
import {check} from "k6";

export let options = {
stages: [
{duration: "60s", target: 100}
]
};

const params = {headers: {"Content-Type": "application/json"}};

const failingSpecResultsXml = open('../test-fixtures/src/main/resources/TEST-projektor.example.spock.FailingSpec.xml');
const passingSpecResultsXml = open('../test-fixtures/src/main/resources/TEST-projektor.example.spock.PassingSpec.xml');

const request = {
groupedTestSuites: [
{
groupName: "group1",
testSuitesBlob: failingSpecResultsXml
},
{
groupName: "group2",
testSuitesBlob: passingSpecResultsXml
}
]
};

const payload = JSON.stringify(request);

export default function () {

const response = http.post(
`http://localhost:8080/groupedResults/`,
payload,
params
);

check(response, {
"status is 200": (r) => r.status === 200
});
};
20 changes: 4 additions & 16 deletions server/test/load-test/postResults.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,18 @@ export let options = {
]
};

const params = { headers: { "Content-Type": "application/json" } };
const params = {headers: {"Content-Type": "application/json"}};

const failingSpecResultsXml = open('../test-fixtures/src/main/resources/TEST-FailingSpec.xml');
const passingSpecResultsXml = open('../test-fixtures/src/main/resources/TEST-PassingSpec.xml');

const request = {
test_results: [
failingSpecResultsXml,
passingSpecResultsXml
]
};
const passingSpecResultsXml = open('../test-fixtures/src/main/resources/TEST-projektor.example.spock.PassingSpec.xml');

export default function () {

const payload = JSON.stringify(request);

const response = http.post(
`http://localhost:8080/results/`,
payload,
passingSpecResultsXml,
params
);

check(response, {
"status is 200": (r) => r.status === 200
})
;
});
};

0 comments on commit f3fdbc2

Please sign in to comment.