Hi! i have runned into some issue, i have this sim...
# ktor
j
Hi! i have runned into some issue, i have this simple get endpoint that returns a large bytearray:
Copy code
package com.example.plugins

import io.ktor.server.application.*
import io.ktor.server.response.*
import io.ktor.server.routing.*

fun Application.configureRouting() {
    routing {
        get("/") {
            val byteArray = ByteArray(400000000)
            call.respondBytes(byteArray)
        }
    }
}
This works fine, but when i try to create a unit test based on this like so:
Copy code
package com.example.plugins

import io.ktor.client.request.*
import io.ktor.http.*
import io.ktor.server.response.*
import io.ktor.server.routing.*
import io.ktor.server.testing.*
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test

internal class RoutingTest {

    @Test
    internal fun `Returns ok on big bytearray`() {
        testApplication {
            application {
                routing {
                    get("/") {
                        val byteArray = ByteArray(400000000)
                        call.respondBytes(byteArray)
                    }
                }
            }
            val response = client.get("/")

            assertEquals(HttpStatusCode.OK, response.status)
        }
    }
}
Then i get this exception:
Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "DefaultDispatcher-worker-1"
Is it my test that are incorrect?
1
g
can you increase the heap size for the test task?
j
Yes, have given it 8192m. But same issue. When i decrease the bytearray from:
Copy code
val byteArray = ByteArray(400000000)
to
Copy code
val byteArray = ByteArray(100000000)
it works fine.
g
i run it locally and apart from taking quite some time (10-15seconds) i didnt get a memory error
j
okay, then its probly some local issue with me and increasing the heap size
Ty
g
maybe you can increase the gradle heap in the ide
j
like this maybe?
Copy code
kotlin.daemon.jvmargs=-Xms4096m -Xmx6048m
g
yes that should work for gradle
j
Nice, got it to work now 😄
hm, the best way for me to increase the heap size only for the test, was this in the build.gradle.kts:
Copy code
tasks {
    test {
        minHeapSize = "1048m"
        maxHeapSize = "2096m"
        useJUnitPlatform {}
        testLogging.showStandardStreams = true
    }
}
g
yes that what i meant with increasing the size for the test 🙂 usually
tasks.withType<Test> {}
which is how its done in latest versions
👍 1