Repository: ktorio/ktor
File: ktor-server/ktor-server-test-suites/jvm/src/io/ktor/server/testing/suites/SustainabilityTestSuite.kt (Kotlin)

Code before:
                createApplicationPlugin("MyPlugin") {
                    onCallRespond { _ ->
                        error("oh nooooo")
                    }
                }
            )

            get {
                call.respondText("hello world")
            }
        }

        withUrl("") {
            assertEquals(HttpStatusCode.InternalServerError, status)
            assertNotNull(loggedException)
            loggedException = null
        }
    }

    @OptIn(ExperimentalCoroutinesApi::class)
    @Test
    open fun validateCallCoroutineContext() = runTest {
        createAndStartServer {
            get {
                val applicationJob = application.coroutineContext[Job] ?: error("application job is empty")
                val callJob = call.coroutineContext[Job] ?: error("call job is empty")
                val hierarchy = generateSequence(callJob) { it.parent }.toList()
                call.respondText(
                    """
                    Hierarchy preserved: ${callJob != applicationJob && applicationJob in hierarchy}
                    """.trimIndent()
                )
            }
        }

        withUrl("") {
            assertEquals(
                """
                Hierarchy preserved: true
                """.trimIndent(),
                body()
            )
        }
    }

    @OptIn(ExperimentalCoroutinesApi::class)
    @Test
    open fun testJobsAreCancelledOnShutdown() = runTest {
        var applicationJob: Job? = null
        var routingJob: Job? = null
        val jobsStartedLatch = CountDownLatch(2)

Review comment (suggestion):
Minor. Could be simplified a bit
```suggestion
                val applicationJob = application.coroutineContext.job
                val callJob = call.coroutineContext.job
```

Code after:
                createApplicationPlugin("MyPlugin") {
                    onCallRespond { _ ->
                        error("oh nooooo")
                    }
                }
            )

            get {
                call.respondText("hello world")
            }
        }

        withUrl("") {
            assertEquals(HttpStatusCode.InternalServerError, status)
            assertNotNull(loggedException)
            loggedException = null
        }
    }

    @OptIn(ExperimentalCoroutinesApi::class)
    @Test
    open fun validateCallCoroutineContext() = runTest {
        createAndStartServer {
            get {
                val applicationJob = application.coroutineContext.job
                val callJob = call.coroutineContext.job
                val hierarchy = generateSequence(callJob) { it.parent }.toList()
                call.respondText(
                    """
                    Hierarchy preserved: ${callJob != applicationJob && applicationJob in hierarchy}
                    """.trimIndent()
                )
            }
        }

        withUrl("") {
            assertEquals(
                """
                Hierarchy preserved: true
                """.trimIndent(),
                body()
            )
        }
    }

    @OptIn(ExperimentalCoroutinesApi::class)
    @Test
    open fun testJobsAreCancelledOnShutdown() = runTest {
        var applicationJob: Job? = null
        var routingJob: Job? = null
        val jobsStartedLatch = CountDownLatch(2)