Files
werkator/src/test/kotlin/de/hoennig/gittally/gitea/GiteaStateMappingTest.kt
T
mhoennigandClaude Fable 5 40f54a1298 Record builds interrupted by a server shutdown as INTERRUPTED, not FAILED
A systemd stop killed the running build process and BuildExecutor
classified the death as FAILED, posting a red Gitea status; FAILED is
not restartable, so the startup recovery never re-enqueued the build.

A ContextClosedEvent listener now sets a shuttingDown flag, terminates
the process trees of executing builds, and drains until their
INTERRUPTED results are persisted. Queued builds stay PENDING without
starting a process; recovery re-enqueues both after the restart.
INTERRUPTED publishes as Gitea state "pending" instead of "failure",
since the build is going to be re-run.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-10 17:26:10 +02:00

35 lines
1.5 KiB
Kotlin

package de.hoennig.gittally.gitea
import de.hoennig.gittally.build.BuildStatus
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.nulls.shouldBeNull
import io.kotest.matchers.shouldBe
class GiteaStateMappingTest :
FunSpec({
test("maps each build status to its Gitea state") {
BuildStatus.SUCCESS.toGiteaState() shouldBe "success"
BuildStatus.FAILED.toGiteaState() shouldBe "failure"
BuildStatus.CANCELLED.toGiteaState() shouldBe "failure"
BuildStatus.PENDING.toGiteaState() shouldBe "pending"
BuildStatus.RUNNING.toGiteaState() shouldBe "pending"
// interrupted builds are re-enqueued on startup, so the commit must not turn red
BuildStatus.INTERRUPTED.toGiteaState() shouldBe "pending"
}
test("maps Gitea states back to build statuses") {
buildStatusFromGiteaState("success") shouldBe BuildStatus.SUCCESS
buildStatusFromGiteaState("failure") shouldBe BuildStatus.FAILED
buildStatusFromGiteaState("error") shouldBe BuildStatus.FAILED
buildStatusFromGiteaState("warning") shouldBe BuildStatus.FAILED
buildStatusFromGiteaState("pending") shouldBe BuildStatus.RUNNING
}
test("maps unknown Gitea states to null") {
buildStatusFromGiteaState("").shouldBeNull()
buildStatusFromGiteaState("deleted").shouldBeNull()
buildStatusFromGiteaState("SUCCESS").shouldBeNull()
}
})