Skip to content

Commit 737380d

Browse files
authored
test(server): add a reproducing test for failure being cached (#1939)
Part of #1938. Adds a test that captures undesired behavior.
1 parent f375ddf commit 737380d

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

jit-binding-server/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ dependencies {
2828
implementation(projects.sharedInternal)
2929

3030
testImplementation("io.ktor:ktor-server-test-host")
31+
testImplementation("io.mockk:mockk:1.14.2")
3132
}
3233

3334
application {

jit-binding-server/src/test/kotlin/io/github/typesafegithub/workflows/jitbindingserver/ArtifactRoutesTest.kt

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
package io.github.typesafegithub.workflows.jitbindingserver
22

3+
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.ActionCoords
34
import io.github.typesafegithub.workflows.mavenbinding.TextArtifact
45
import io.kotest.core.spec.style.FunSpec
56
import io.kotest.matchers.shouldBe
67
import io.ktor.client.request.get
78
import io.ktor.client.statement.bodyAsText
89
import io.ktor.http.HttpStatusCode
910
import io.ktor.server.testing.testApplication
11+
import io.mockk.every
12+
import io.mockk.mockk
13+
import io.mockk.verify
1014

1115
class ArtifactRoutesTest :
1216
FunSpec({
@@ -64,5 +68,38 @@ class ArtifactRoutesTest :
6468
response.status shouldBe HttpStatusCode.InternalServerError
6569
}
6670
}
71+
72+
test("when binding generation fails and then succeeds, and two requests are made") {
73+
testApplication {
74+
// Given
75+
val mockBuildVersionArtifacts = mockk<(ActionCoords) -> Map<String, TextArtifact>?>()
76+
every { mockBuildVersionArtifacts(any()) } throws
77+
Exception("An internal error occurred!") andThen
78+
mapOf("some-action-v4.pom" to TextArtifact { "Some POM contents" })
79+
application {
80+
appModule(
81+
buildVersionArtifacts = mockBuildVersionArtifacts,
82+
)
83+
}
84+
85+
// When
86+
val response = client.get("some-owner/some-action/v4/some-action-v4.pom")
87+
// Then
88+
response.status shouldBe HttpStatusCode.InternalServerError
89+
90+
// When
91+
val response2 = client.get("some-owner/some-action/v4/some-action-v4.pom")
92+
// Then
93+
// This assertion represents an undesired behavior - it should retry generating the binding
94+
// and return the actual POM.
95+
// TODO fix in https://github.com/typesafegithub/github-workflows-kt/issues/1938
96+
response2.status shouldBe HttpStatusCode.InternalServerError
97+
98+
// This assertion represents an undesired behavior - it should call the binding generation twice,
99+
// first with exception, and then when it's successful.
100+
// TODO fix in https://github.com/typesafegithub/github-workflows-kt/issues/1938
101+
verify(exactly = 1) { mockBuildVersionArtifacts(any()) }
102+
}
103+
}
67104
}
68105
})

0 commit comments

Comments
 (0)