Skip to content

Commit

Permalink
Merge pull request #66 from craigatk/min-compress
Browse files Browse the repository at this point in the history
(feature) Only compressing responses if they are over 1K
  • Loading branch information
craigatk committed Apr 13, 2020
2 parents ac84ade + fd04213 commit 3f18ea4
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 13 deletions.
1 change: 1 addition & 0 deletions server/server-app/src/main/kotlin/projektor/Application.kt
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ fun Application.main() {
install(Compression) {
gzip {
matchContentType(ContentType.Application.Json, ContentType.Application.JavaScript)
minimumSize(1024)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,19 @@ class GetTestRunCompressionApplicationTest : ApplicationTestCase() {
fun `when gzip accept header included should compress test run response`() {
val publicId = randomPublicId()

val testSuiteCount = 200

withTestApplication(::createTestApplication) {
handleRequest(HttpMethod.Get, "/run/$publicId") {
testRunDBGenerator.createTestRun(
publicId,
listOf(
TestSuiteData("testSuite1",
listOf("testSuite1TestCase1", "testSuite1TestCase2"),
listOf(),
listOf()
),
TestSuiteData("testSuite2",
listOf("testSuite2TestCase1", "testSuite2TestCase2", "testSuite2TestCase3"),
listOf(),
listOf()
)
)
(1..testSuiteCount).map {
TestSuiteData("reallyLongNameForTestSuite$it",
listOf("testSuite${it}TestCase1", "testSuite${it}TestCase2"),
listOf(),
listOf()
)
}
)

addHeader(HttpHeaders.AcceptEncoding, "gzip")
Expand All @@ -57,7 +54,42 @@ class GetTestRunCompressionApplicationTest : ApplicationTestCase() {

val testSuites = responseRun.testSuites
assertNotNull(testSuites)
expectThat(testSuites).hasSize(2)
expectThat(testSuites).hasSize(testSuiteCount)
}
}
}

@Test
fun `when gzip accept header included but request tiny should not compress test run response`() {
val publicId = randomPublicId()

val testSuiteCount = 2

withTestApplication(::createTestApplication) {
handleRequest(HttpMethod.Get, "/run/$publicId") {
testRunDBGenerator.createTestRun(
publicId,
(1..testSuiteCount).map {
TestSuiteData("shortTestSuite$it",
listOf("testSuite${it}TestCase1", "testSuite${it}TestCase2"),
listOf(),
listOf()
)
}
)

addHeader(HttpHeaders.AcceptEncoding, "gzip")
}.apply {
expectThat(response.status()).isEqualTo(HttpStatusCode.OK)

val responseRun = objectMapper.readValue(response.content, TestRun::class.java)
assertNotNull(responseRun)

expectThat(responseRun.id).isEqualTo(publicId.id)

val testSuites = responseRun.testSuites
assertNotNull(testSuites)
expectThat(testSuites).hasSize(testSuiteCount)
}
}
}
Expand Down

0 comments on commit 3f18ea4

Please sign in to comment.