Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for can auto-reload on ktor #1797

Merged
merged 2 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ import io.ktor.server.application.hooks.*
import io.ktor.util.*
import org.koin.core.KoinApplication
import org.koin.core.context.startKoin
import org.koin.core.context.stopKoin
import org.koin.core.scope.Scope
import org.koin.dsl.KoinAppDeclaration
import org.koin.mp.KoinPlatformTools

/**
* @author Arnaud Giuliani
Expand All @@ -34,6 +36,7 @@ import org.koin.dsl.KoinAppDeclaration
*/
val Koin = createApplicationPlugin(name = "Koin", createConfiguration = { KoinApplication.init() }) {
val koinApplication = setupKoinApplication()
KoinPlatformTools.defaultContext().getOrNull()?.let { stopKoin() } // for ktor auto-reload
startKoin(koinApplication)
setupMonitoring(koinApplication)
setupKoinScope(koinApplication)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,29 @@ class KoinPluginRunTest {
s.stop()
assert(counter == 1){ "counter should 1 - instance is created" }
}

@Test
@Ignore // socket exception on GH
fun `should can reload`() = runBlocking<Unit> {
val koinModule = module {
single<String> {
"Reproduction test"
}
}
val s = embeddedServer(
Netty,
module = {
install(Koin) {
modules(koinModule)
}
},
).start(false)
delay(500)

// verify for can auto-reload
(s.environment as ApplicationEngineEnvironmentReloading).reload()
s.stop()
}
}

private fun testMyApplication(test: suspend (jsonClient: HttpClient) -> Unit) = testApplication {
Expand Down