From a8e43d6f5069f798d9236db96a347a369aa206ae Mon Sep 17 00:00:00 2001 From: Dmitry Khalanskiy Date: Thu, 28 Oct 2021 14:41:18 +0300 Subject: [PATCH] Add lost tests --- .../common/test/RunTestTest.kt | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/kotlinx-coroutines-test/common/test/RunTestTest.kt b/kotlinx-coroutines-test/common/test/RunTestTest.kt index d64e7c327e..fbca2b05ac 100644 --- a/kotlinx-coroutines-test/common/test/RunTestTest.kt +++ b/kotlinx-coroutines-test/common/test/RunTestTest.kt @@ -217,4 +217,38 @@ class RunTestTest { } }) + /** Tests that [runTest] completes its job. */ + @Test + fun testCompletesOwnJob(): TestResult { + var handlerCalled = false + return testResultMap({ + it() + assertTrue(handlerCalled) + }, { + runTest { + coroutineContext.job.invokeOnCompletion { + handlerCalled = true + } + } + }) + } + + /** Tests that [runTest] doesn't complete the job that was passed to it as an argument. */ + @Test + fun testDoesNotCompleteGivenJob(): TestResult { + var handlerCalled = false + val job = Job() + job.invokeOnCompletion { + handlerCalled = true + } + return testResultMap({ + it() + assertFalse(handlerCalled) + assertEquals(0, job.children.filter { it.isActive }.count()) + }, { + runTest(job) { + assertTrue(coroutineContext.job in job.children) + } + }) + } }