Hello, I just tried updating Koin to 3.5.0 but the...
# koin
d
Hello, I just tried updating Koin to 3.5.0 but the following test (see thread) works with Koin 3.4.3 but fails with 3.5.0 with
expected:<200 OK> but was:<404 Not Found>
It seems like the
init{}
block of the
KtorMyModule
is not executed any more although it is configured with
createdAtStart = true
.
Copy code
import io.kotest.matchers.shouldBe
import io.kotest.matchers.string.shouldContain
import io.ktor.client.HttpClient
import io.ktor.client.request.get
import io.ktor.client.statement.bodyAsText
import io.ktor.http.HttpStatusCode
import io.ktor.server.application.*
import io.ktor.server.response.respond
import io.ktor.server.routing.*
import io.ktor.server.testing.testApplication
import org.junit.jupiter.api.Test
import org.koin.dsl.module
import org.koin.ktor.plugin.Koin

class ReproducerTest {

    @Test
    fun `minimalistic reproducer`() {
        testMyApplication {
            val response = it.get("testurl") {}

            response.status.shouldBe(HttpStatusCode.OK)
            response.bodyAsText().shouldContain("Test response")
        }
    }

    private fun testMyApplication(test: suspend (jsonClient: HttpClient) -> Unit) = testApplication {
        application {
            install(Koin) {
                modules(
                    module {
                        single { this@application }
                        single(createdAtStart = true) { KtorMyModule(get()) }
                    },
                )
            }
        }
        test.invoke(createClient {})
    }
}

class KtorMyModule(application: Application) {
    init {
        application.routing {
            get("testurl") { call.respond(HttpStatusCode.OK, "Test response") }
        }
    }
}
a
3.5.0 deployment seems laggy or something on maven central ... I'm checking
d
That’s not the issue, the artifact is downloaded. The issue is a changed behavior somehow.
a
can you add debug? with
slf4jLogger(DEBUG)
👍 1
I've spotted it out. A contributor PR screwed the ktor start, for isolation context ... something I've not seen
👍 1
d
3.4.3:
Copy code
15:41:13.635 [DefaultDispatcher-worker-1 @call-context#2] INFO  ktor.test - No ktor.deployment.watch patterns specified, automatic reload is not active.
15:41:13.684 [DefaultDispatcher-worker-1 @call-context#2] DEBUG [Koin] - (+) index 'KtorMyModule::_root_' -> '[Singleton:'KtorMyModule']'
15:41:13.684 [DefaultDispatcher-worker-1 @call-context#2] DEBUG [Koin] - (+) index 'io.ktor.server.application.Application::_root_' -> '[Singleton:'io.ktor.server.application.Application']'
15:41:13.685 [DefaultDispatcher-worker-1 @call-context#2] DEBUG [Koin] - loaded 2 definitions in 1.206667 ms
15:41:13.687 [DefaultDispatcher-worker-1 @call-context#2] DEBUG [Koin] - Eager instances ...
15:41:13.688 [DefaultDispatcher-worker-1 @call-context#2] DEBUG [Koin] - | (+) '[Singleton:'KtorMyModule']'
15:41:13.689 [DefaultDispatcher-worker-1 @call-context#2] DEBUG [Koin] - |- 'io.ktor.server.application.Application' ...
15:41:13.689 [DefaultDispatcher-worker-1 @call-context#2] DEBUG [Koin] - | (+) '[Singleton:'io.ktor.server.application.Application']'
15:41:13.689 [DefaultDispatcher-worker-1 @call-context#2] DEBUG [Koin] - |- 'io.ktor.server.application.Application' in 0.088958 ms
15:41:13.707 [DefaultDispatcher-worker-1 @call-context#2] DEBUG [Koin] - Eager instances created in 20.04725 ms
15:41:13.708 [DefaultDispatcher-worker-1 @call-context#2] INFO  ktor.test - Application started in 0.085 seconds.
15:41:14.065 [Test worker] DEBUG [Koin] - |- (-) Scope - id:'_root_'
3.5.0:
Copy code
15:33:28.495 [DefaultDispatcher-worker-1 @call-context#2] INFO  ktor.test - No ktor.deployment.watch patterns specified, automatic reload is not active.
15:33:28.546 [DefaultDispatcher-worker-1 @call-context#2] DEBUG [Koin] - (+) index 'KtorMyModule::_root_' -> '[Singleton:'KtorMyModule']'
15:33:28.547 [DefaultDispatcher-worker-1 @call-context#2] DEBUG [Koin] - (+) index 'io.ktor.server.application.Application::_root_' -> '[Singleton:'io.ktor.server.application.Application']'
15:33:28.547 [DefaultDispatcher-worker-1 @call-context#2] DEBUG [Koin] - Koin started with 2 definitions in 1.310375 ms
15:33:28.550 [DefaultDispatcher-worker-1 @call-context#2] INFO  ktor.test - Application started in 0.066 seconds.
15:33:28.606 [DefaultDispatcher-worker-1 @request#2] DEBUG [Koin] - |- (+) Scope - id:'org.koin.ktor.plugin.RequestScope@1295830128' q:q:'org.koin.ktor.plugin.RequestScope'
15:33:28.606 [DefaultDispatcher-worker-1 @request#2] DEBUG [Koin] - | Scope 'q:'org.koin.ktor.plugin.RequestScope'' not defined. Creating it ...
15:33:28.885 [DefaultDispatcher-worker-1 @request#2] DEBUG [Koin] - |- (-) Scope - id:'org.koin.ktor.plugin.RequestScope@1295830128'

Expected :200 OK
Actual   :404 Not Found
<Click to see difference>

io.kotest.assertions.AssertionFailedError: expected:<200 OK> but was:<404 Not Found>
	...
Oh, you were quicker, just wanted to make sure it wasn't some unintended usage on our side 😂 Happily waiting for the next version then 🙂
a
it's a side effect of one PR. eager instances are not created