Skip to content

Commit

Permalink
more deterministic `IntersectionScopeTest.completed child does not le…
Browse files Browse the repository at this point in the history
…ak through parent`

GitOrigin-RevId: 770b2345eb7ab7a1155eb82d431a5054226b9b6e
  • Loading branch information
dovchinnikov authored and intellij-monorepo-bot committed Feb 24, 2023
1 parent 96a3ad3 commit 19a86b7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
}
}

Expand Down

0 comments on commit 19a86b7

Please sign in to comment.