Skip to content

Commit

Permalink
Merge pull request #82 from craigatk/deleted-status
Browse files Browse the repository at this point in the history
(feature) Setting the status on results processing to deleted
  • Loading branch information
craigatk authored Apr 29, 2020
2 parents 938a578 + 4706809 commit b11349c
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ enum class ResultsProcessingStatus {
RECEIVED,
PROCESSING,
SUCCESS,
DELETED,
ERROR
}
4 changes: 3 additions & 1 deletion server/server-app/src/main/kotlin/projektor/Application.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import projektor.database.DataSourceConfig
import projektor.incomingresults.GroupedTestResultsService
import projektor.incomingresults.TestResultsProcessingService
import projektor.incomingresults.TestResultsService
import projektor.incomingresults.processing.ResultsProcessingRepository
import projektor.metrics.InfluxMetricsConfig
import projektor.metrics.createRegistry
import projektor.route.*
Expand Down Expand Up @@ -116,12 +117,13 @@ fun Application.main() {
val testSuiteService: TestSuiteService by inject()
val testRunSystemAttributesService: TestRunSystemAttributesService by inject()
val testRunRepository: TestRunRepository by inject()
val resultsProcessingRepository: ResultsProcessingRepository by inject()

val attachmentRepository: AttachmentRepository by inject()
val attachmentService = conditionallyCreateAttachmentService(applicationConfig, attachmentRepository)
attachmentService?.conditionallyCreateBucketIfNotExists()

val cleanupService = CleanupService(cleanupConfig, testRunRepository, attachmentService)
val cleanupService = CleanupService(cleanupConfig, testRunRepository, resultsProcessingRepository, attachmentService)
val scheduler: Scheduler by inject()
CleanupScheduledJob.conditionallyStartCleanupScheduledJob(cleanupConfig, cleanupService, scheduler)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ import java.lang.Exception
import java.time.LocalDate
import org.slf4j.LoggerFactory
import projektor.attachment.AttachmentService
import projektor.incomingresults.processing.ResultsProcessingRepository
import projektor.server.api.PublicId
import projektor.server.api.results.ResultsProcessingStatus
import projektor.testrun.TestRunRepository

@KtorExperimentalAPI
class CleanupService(
private val cleanupConfig: CleanupConfig,
private val testRunRepository: TestRunRepository,
private val resultsProcessingRepository: ResultsProcessingRepository,
private val attachmentService: AttachmentService?
) {
private val logger = LoggerFactory.getLogger(javaClass.canonicalName)
Expand Down Expand Up @@ -40,6 +43,8 @@ class CleanupService(
testRunRepository.deleteTestRun(publicId)

attachmentService?.deleteAttachments(publicId)

resultsProcessingRepository.updateResultsProcessingStatus(publicId, ResultsProcessingStatus.DELETED)
}

private suspend fun conditionallyCleanupTestRun(publicId: PublicId, cleanupConfig: CleanupConfig): PublicId? =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package projektor.cleanup

import io.ktor.util.KtorExperimentalAPI
import java.io.File
import java.sql.Timestamp
import java.time.Instant
import java.time.LocalDate
import kotlinx.coroutines.runBlocking
import org.junit.jupiter.api.Test
Expand All @@ -11,7 +13,9 @@ import projektor.TestSuiteData
import projektor.attachment.AttachmentConfig
import projektor.attachment.AttachmentDatabaseRepository
import projektor.attachment.AttachmentService
import projektor.database.generated.tables.pojos.ResultsProcessing
import projektor.incomingresults.randomPublicId
import projektor.server.api.results.ResultsProcessingStatus
import strikt.api.expectThat
import strikt.assertions.*

Expand All @@ -23,6 +27,7 @@ class CleanupServiceTest : DatabaseRepositoryTestCase() {
val cleanupService = CleanupService(
CleanupConfig(true, 30, false),
get(),
get(),
null
)

Expand Down Expand Up @@ -66,6 +71,7 @@ class CleanupServiceTest : DatabaseRepositoryTestCase() {
val cleanupService = CleanupService(
CleanupConfig(true, 30, false),
get(),
get(),
null
)

Expand Down Expand Up @@ -110,6 +116,43 @@ class CleanupServiceTest : DatabaseRepositoryTestCase() {
expectThat(testSuiteGroupDao.fetchOneById(testGroup2.id)).isNull()
}

@Test
fun `should update processing status to 'deleted'`() {
val cleanupService = CleanupService(
CleanupConfig(true, 30, false),
get(),
get(),
null
)

val publicId = randomPublicId()

resultsProcessingDao.insert(ResultsProcessing()
.setPublicId(publicId.id)
.setCreatedTimestamp(Timestamp.from(Instant.now()))
.setStatus(ResultsProcessingStatus.SUCCESS.name)
)

testRunDBGenerator.createTestRun(publicId,
listOf(
TestSuiteData(
"testSuite1",
listOf("testSuite1PassedTestCase1", "testSuite1PassedTestCase2"),
listOf(),
listOf()
)
)
)

runBlocking { cleanupService.cleanupTestRun(publicId) }

expectThat(resultsProcessingDao.fetchOneByPublicId(publicId.id))
.isNotNull()
.and {
get { status }.isEqualTo(ResultsProcessingStatus.DELETED.name)
}
}

@Test
fun `should delete test run with attachments`() {
val attachmentsConfig = AttachmentConfig(
Expand All @@ -127,6 +170,7 @@ class CleanupServiceTest : DatabaseRepositoryTestCase() {
val cleanupService = CleanupService(
CleanupConfig(true, 30, false),
get(),
get(),
attachmentService
)

Expand Down Expand Up @@ -183,7 +227,7 @@ class CleanupServiceTest : DatabaseRepositoryTestCase() {

val cleanupConfig = CleanupConfig(false, null, false)

val cleanupService = CleanupService(cleanupConfig, get(), null)
val cleanupService = CleanupService(cleanupConfig, get(), get(), null)

val cleanedUpTestRuns = runBlocking { cleanupService.conditionallyExecuteCleanup() }

Expand All @@ -207,7 +251,7 @@ class CleanupServiceTest : DatabaseRepositoryTestCase() {
testRunDBGenerator.createTestRun(pinnedTestRunId, LocalDate.now().minusDays(31), true)

val cleanupConfig = CleanupConfig(true, 30, false)
val cleanupService = CleanupService(cleanupConfig, get(), null)
val cleanupService = CleanupService(cleanupConfig, get(), get(), null)

val cleanedUpTestRuns = runBlocking { cleanupService.conditionallyExecuteCleanup() }

Expand All @@ -231,7 +275,7 @@ class CleanupServiceTest : DatabaseRepositoryTestCase() {
testRunDBGenerator.createTestRun(testRunIdTooOld2, LocalDate.now().minusDays(45), false)

val cleanupConfig = CleanupConfig(true, 30, true)
val cleanupService = CleanupService(cleanupConfig, get(), null)
val cleanupService = CleanupService(cleanupConfig, get(), get(), null)

val cleanedUpTestRuns = runBlocking { cleanupService.conditionallyExecuteCleanup() }

Expand Down

0 comments on commit b11349c

Please sign in to comment.