From 19a86b7d7c88d67fd2e6de63a9f12e2d6fbb7411 Mon Sep 17 00:00:00 2001 From: Daniil Ovchinnikov Date: Thu, 23 Feb 2023 17:19:00 +0100 Subject: [PATCH] more deterministic `IntersectionScopeTest.completed child does not leak through parent` GitOrigin-RevId: 770b2345eb7ab7a1155eb82d431a5054226b9b6e --- .../com/intellij/openapi/application/impl/util.kt | 6 ++++++ .../com/intellij/util/IntersectionScopeTest.kt | 13 ++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/application/impl/util.kt b/platform/platform-tests/testSrc/com/intellij/openapi/application/impl/util.kt index 6c22e8ad933d5..86e08b69c664f 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/application/impl/util.kt +++ b/platform/platform-tests/testSrc/com/intellij/openapi/application/impl/util.kt @@ -41,6 +41,12 @@ fun assertReferenced(root: Any, referenced: Any) { assertNotNull(foundObjects.find { it === referenced }) } +fun assertNotReferenced(root: Any, referenced: Any) { + LeakHunter.checkLeak(root, referenced::class.java) { potentialLeak -> + potentialLeak === referenced + } +} + /** * @see com.intellij.util.ui.UIUtil.pump */ diff --git a/platform/platform-tests/testSrc/com/intellij/util/IntersectionScopeTest.kt b/platform/platform-tests/testSrc/com/intellij/util/IntersectionScopeTest.kt index 4a3625d66a008..ce155e1fff485 100644 --- a/platform/platform-tests/testSrc/com/intellij/util/IntersectionScopeTest.kt +++ b/platform/platform-tests/testSrc/com/intellij/util/IntersectionScopeTest.kt @@ -1,9 +1,9 @@ // Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.util +import com.intellij.openapi.application.impl.assertNotReferenced import com.intellij.openapi.application.impl.assertReferenced import com.intellij.openapi.progress.timeoutRunBlocking -import com.intellij.testFramework.LeakHunter import com.intellij.testFramework.junit5.TestApplication import kotlinx.coroutines.* import kotlinx.coroutines.sync.Semaphore @@ -165,14 +165,13 @@ class IntersectionScopeTest { @Test fun `completed child does not leak through parent`(): Unit = timeoutRunBlocking { val parentJob = Job() - val childJob = launch(start = CoroutineStart.UNDISPATCHED) { - attachAsChildTo(CoroutineScope(parentJob)) - awaitCancellation() - } + val childJob = Job() + CoroutineScope(childJob).attachAsChildTo(CoroutineScope(parentJob)) assertReferenced(parentJob, childJob) + val childHandleJob = parentJob.children.single() childJob.cancel() - parentJob.children.single().join() // wait for completion of job which waits for completion of the child - LeakHunter.checkLeak(parentJob, childJob::class.java) + childHandleJob.join() + assertNotReferenced(parentJob, childJob) } }