From d599b54f4e2e117c7699fc319ecc575bf01488e3 Mon Sep 17 00:00:00 2001 From: akotynski Date: Thu, 2 Nov 2023 12:00:51 +0100 Subject: [PATCH] KTOR-6411 resolve connectors in the test engine (#3798) --- .../io/ktor/server/testing/TestApplicationEngine.kt | 1 + .../jvmAndNix/test/TestApplicationTest.kt | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/ktor-server/ktor-server-test-host/jvmAndNix/src/io/ktor/server/testing/TestApplicationEngine.kt b/ktor-server/ktor-server-test-host/jvmAndNix/src/io/ktor/server/testing/TestApplicationEngine.kt index 12bb3aac83d..7cd9d0935a0 100644 --- a/ktor-server/ktor-server-test-host/jvmAndNix/src/io/ktor/server/testing/TestApplicationEngine.kt +++ b/ktor-server/ktor-server-test-host/jvmAndNix/src/io/ktor/server/testing/TestApplicationEngine.kt @@ -144,6 +144,7 @@ class TestApplicationEngine( environment.start() cancellationDeferred = stopServerOnCancellation() applicationStarting.complete() + resolvedConnectors.complete(runBlocking { resolvedConnectors() }) state.value = State.Started } if (state.value == State.Starting) { diff --git a/ktor-server/ktor-server-test-host/jvmAndNix/test/TestApplicationTest.kt b/ktor-server/ktor-server-test-host/jvmAndNix/test/TestApplicationTest.kt index 616648b8eb9..08e9753e767 100644 --- a/ktor-server/ktor-server-test-host/jvmAndNix/test/TestApplicationTest.kt +++ b/ktor-server/ktor-server-test-host/jvmAndNix/test/TestApplicationTest.kt @@ -374,6 +374,17 @@ class TestApplicationTest { assertEquals("8081", response8081.bodyAsText()) } + @Test + fun testStartupJobsCompletion() = testApplication { + startApplication() + val childrenJobsSize = engine.application.coroutineContext.job.children.toList().size + assertEquals( + expected = 0, + actual = childrenJobsSize, + message = "all the children jobs should be completed", + ) + } + @Test fun testCanPassCoroutineContextFromOutside() = runBlocking(MyElement("test")) { testApplication(coroutineContext) {