https://kotlinlang.org logo
#ktor
Title
# ktor
t

twisterrob

02/15/2020, 3:54 PM
Hi, I get this message when doing tests:
[Test worker] ktor.test(ApplicationEngineEnvironmentReloading.kt:135) No
ktor.deployment.watch
patterns specified, automatic reload is not active
This is how I use tests (ktor 1.3.1):
Copy code
private fun endpointTest(test: TestApplicationEngine.() -> Unit) {
   withTestApplication(
      { /* I apply my `fun Application.module()` setup here */ },
      test
   )
}
How can I fix that message?
I know it is safe, and just an info, but right now 20% of my test run output is polluted with this.
withTestApplication
doesn't have the same
watchPaths
parameter as
embeddedServer
and I can't find another way to set
watchPaths
via
Application.*
.
Tried
Copy code
fun Application.configuration() {
	(environment.config as? MapApplicationConfig)?.apply {
		if (propertyOrNull("ktor.deployment.watch") === null) {
			put(
				"ktor.deployment.watch",
				"silence 'No ktor.deployment.watch patterns specified' in ApplicationEngineEnvironmentReloading"
			)
		}
	}
but
ApplicationEngineEnvironmentReloading
caches the value at construction time (not startup), so this change doesn't propagate.
This got the config property to where I need it:
Copy code
private fun endpointTest(test: TestApplicationEngine.() -> Unit) {
	withApplication(
		environment = createTestEnvironment {
			(config as? MapApplicationConfig)?.apply {
				if (propertyOrNull("ktor.deployment.watch") === null) {
					put(
						"ktor.deployment.watch",
						listOf("silence 'No ktor.deployment.watch patterns specified' in ApplicationEngineEnvironmentReloading")
					)
				}
			}
		}
	) {
		/* I apply my `fun Application.module()` setup here */
		test()
	}
}
but now I'm getting a full classpath listing and
No ktor.deployment.watch patterns match classpath entries, automatic reload is not active
Is there no way to disable reloading?!
I was thinking about disabling the log for this class, but this is on
ktor.test
logger which means that I would lose all test logging 😞
ok, I give up, this works, but pretty hacky 😅 :
Copy code
withApplication(
	environment = createTestEnvironment {
		val originalLog = log
		log = object : Logger by originalLog {
			override fun info(msg: String?) {
				when (msg) {
					"No ktor.deployment.watch patterns specified, automatic reload is not active" -> Unit
					else -> <http://originalLog.info|originalLog.info>(msg)
				}
			}
		}
	}
)
c

christoph.pickl

02/16/2020, 11:41 AM
@twisterrob i felt exactly the same annoyance towards this message... well, i guess i will just live with it (although some kind of "hacky solution" and just hide it sounds tempting 😆 )
2 Views