Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix potential crash in Rx2 and Rx3 asFlow extension
- Loading branch information
Showing
4 changed files
with
85 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
reactive/kotlinx-coroutines-rx2/test/ObservableSourceAsFlowStressTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
package kotlinx.coroutines.rx2 | ||
|
||
import io.reactivex.* | ||
import kotlinx.coroutines.* | ||
import kotlinx.coroutines.channels.* | ||
import kotlinx.coroutines.flow.* | ||
import org.junit.* | ||
import java.util.concurrent.* | ||
|
||
class ObservableSourceAsFlowStressTest : TestBase() { | ||
|
||
private val iterations = 100 * stressTestMultiplierSqrt | ||
|
||
@Before | ||
fun setup() { | ||
ignoreLostThreads("RxComputationThreadPool-", "RxCachedWorkerPoolEvictor-", "RxSchedulerPurge-") | ||
} | ||
|
||
@Test | ||
fun testAsFlowCancellation() = runTest { | ||
repeat(iterations) { | ||
val latch = Channel<Unit>(1) | ||
var i = 0 | ||
val observable = Observable.interval(100L, TimeUnit.MICROSECONDS) | ||
.doOnNext { if (++i > 100) latch.offer(Unit) } | ||
val job = observable.asFlow().launchIn(CoroutineScope(Dispatchers.Default)) | ||
latch.receive() | ||
job.cancelAndJoin() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
reactive/kotlinx-coroutines-rx3/test/ObservableSourceAsFlowStressTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
package kotlinx.coroutines.rx3 | ||
|
||
import io.reactivex.rxjava3.core.* | ||
import io.reactivex.rxjava3.exceptions.* | ||
import kotlinx.coroutines.* | ||
import kotlinx.coroutines.channels.* | ||
import kotlinx.coroutines.flow.* | ||
import org.junit.* | ||
import java.util.concurrent.* | ||
|
||
class ObservableSourceAsFlowStressTest : TestBase() { | ||
|
||
private val iterations = 100 * stressTestMultiplierSqrt | ||
|
||
@Before | ||
fun setup() { | ||
ignoreLostThreads("RxComputationThreadPool-", "RxCachedWorkerPoolEvictor-", "RxSchedulerPurge-") | ||
} | ||
|
||
@Test | ||
fun testAsFlowCancellation() = runTest { | ||
repeat(iterations) { | ||
val latch = Channel<Unit>(1) | ||
var i = 0 | ||
val observable = Observable.interval(100L, TimeUnit.MICROSECONDS) | ||
.doOnNext { if (++i > 100) latch.offer(Unit) } | ||
val job = observable.asFlow().launchIn(CoroutineScope(Dispatchers.Default)) | ||
latch.receive() | ||
job.cancelAndJoin() | ||
} | ||
} | ||
} |