Structured concurrency in tests (removed explicit coroutineContext)
diff --git a/core/kotlinx-coroutines-core/test/AsyncJvmTest.kt b/core/kotlinx-coroutines-core/test/AsyncJvmTest.kt
index 7de2ff7..b30c8bc 100644
--- a/core/kotlinx-coroutines-core/test/AsyncJvmTest.kt
+++ b/core/kotlinx-coroutines-core/test/AsyncJvmTest.kt
@@ -13,7 +13,7 @@
expect(1)
@Suppress("UNREACHABLE_CODE")
- val d = async(coroutineContext) {
+ val d = async {
expect(3)
try {
yield() // to main, will cancel
diff --git a/core/kotlinx-coroutines-core/test/AtomicCancellationTest.kt b/core/kotlinx-coroutines-core/test/AtomicCancellationTest.kt
index 0507484..3de6015 100644
--- a/core/kotlinx-coroutines-core/test/AtomicCancellationTest.kt
+++ b/core/kotlinx-coroutines-core/test/AtomicCancellationTest.kt
@@ -6,8 +6,6 @@
import kotlinx.coroutines.experimental.channels.*
import kotlinx.coroutines.experimental.selects.*
-import kotlinx.coroutines.experimental.sync.*
-import kotlin.coroutines.experimental.*
import kotlin.test.*
class AtomicCancellationTest : TestBase() {
@@ -15,7 +13,7 @@
fun testSendAtomicCancel() = runBlocking {
expect(1)
val channel = Channel<Int>()
- val job = launch(coroutineContext, start = CoroutineStart.UNDISPATCHED) {
+ val job = launch(start = CoroutineStart.UNDISPATCHED) {
expect(2)
channel.send(42) // suspends
expect(4) // should execute despite cancellation
@@ -31,7 +29,7 @@
fun testSelectSendAtomicCancel() = runBlocking {
expect(1)
val channel = Channel<Int>()
- val job = launch(coroutineContext, start = CoroutineStart.UNDISPATCHED) {
+ val job = launch(start = CoroutineStart.UNDISPATCHED) {
expect(2)
val result = select<String> { // suspends
channel.onSend(42) {
@@ -53,7 +51,7 @@
fun testReceiveAtomicCancel() = runBlocking {
expect(1)
val channel = Channel<Int>()
- val job = launch(coroutineContext, start = CoroutineStart.UNDISPATCHED) {
+ val job = launch(start = CoroutineStart.UNDISPATCHED) {
expect(2)
assertEquals(42, channel.receive()) // suspends
expect(4) // should execute despite cancellation
@@ -69,7 +67,7 @@
fun testSelectReceiveAtomicCancel() = runBlocking {
expect(1)
val channel = Channel<Int>()
- val job = launch(coroutineContext, start = CoroutineStart.UNDISPATCHED) {
+ val job = launch(start = CoroutineStart.UNDISPATCHED) {
expect(2)
val result = select<String> { // suspends
channel.onReceive {
@@ -91,18 +89,18 @@
@Test
fun testSelectDeferredAwaitCancellable() = runBlocking {
expect(1)
- val deferred = async(coroutineContext) { // deferred, not yet complete
+ val deferred = async { // deferred, not yet complete
expect(4)
"OK"
}
assertEquals(false, deferred.isCompleted)
var job: Job? = null
- launch(coroutineContext) { // will cancel job as soon as deferred completes
+ launch { // will cancel job as soon as deferred completes
expect(5)
assertEquals(true, deferred.isCompleted)
job!!.cancel()
}
- job = launch(coroutineContext, start = CoroutineStart.UNDISPATCHED) {
+ job = launch(start = CoroutineStart.UNDISPATCHED) {
expect(2)
try {
select<Unit> { // suspends
@@ -121,17 +119,17 @@
@Test
fun testSelectJobJoinCancellable() = runBlocking {
expect(1)
- val jobToJoin = launch(coroutineContext) { // not yet complete
+ val jobToJoin = launch { // not yet complete
expect(4)
}
assertEquals(false, jobToJoin.isCompleted)
var job: Job? = null
- launch(coroutineContext) { // will cancel job as soon as jobToJoin completes
+ launch { // will cancel job as soon as jobToJoin completes
expect(5)
assertEquals(true, jobToJoin.isCompleted)
job!!.cancel()
}
- job = launch(coroutineContext, start = CoroutineStart.UNDISPATCHED) {
+ job = launch(start = CoroutineStart.UNDISPATCHED) {
expect(2)
try {
select<Unit> { // suspends
diff --git a/core/kotlinx-coroutines-core/test/CoroutinesJvmTest.kt b/core/kotlinx-coroutines-core/test/CoroutinesJvmTest.kt
index 80731d8..d693cde 100644
--- a/core/kotlinx-coroutines-core/test/CoroutinesJvmTest.kt
+++ b/core/kotlinx-coroutines-core/test/CoroutinesJvmTest.kt
@@ -23,11 +23,11 @@
@Test
fun testCancelManyCompletedAttachedChildren() = runTest {
- val parent = launch(coroutineContext) { /* do nothing */ }
+ val parent = launch { /* do nothing */ }
val n = 10_000 * stressTestMultiplier
repeat(n) {
// create a child that already completed
- val child = launch(coroutineContext, CoroutineStart.UNDISPATCHED) { /* do nothing */ }
+ val child = launch(start = CoroutineStart.UNDISPATCHED) { /* do nothing */ }
// attach it manually
parent.attachChild(child)
}
diff --git a/core/kotlinx-coroutines-core/test/DebugThreadNameTest.kt b/core/kotlinx-coroutines-core/test/DebugThreadNameTest.kt
index a42f945..06f9f4b 100644
--- a/core/kotlinx-coroutines-core/test/DebugThreadNameTest.kt
+++ b/core/kotlinx-coroutines-core/test/DebugThreadNameTest.kt
@@ -4,7 +4,6 @@
package kotlinx.coroutines.experimental
-import kotlin.coroutines.experimental.*
import kotlin.test.*
class DebugThreadNameTest : TestBase() {
@@ -16,7 +15,7 @@
@Test
fun testLaunchId() = runTest {
assertName("coroutine#1")
- launch(coroutineContext) {
+ launch {
assertName("coroutine#2")
yield()
assertName("coroutine#2")
@@ -27,7 +26,7 @@
@Test
fun testLaunchIdUndispatched() = runTest {
assertName("coroutine#1")
- launch(coroutineContext, start = CoroutineStart.UNDISPATCHED) {
+ launch(start = CoroutineStart.UNDISPATCHED) {
assertName("coroutine#2")
yield()
assertName("coroutine#2")
@@ -38,7 +37,7 @@
@Test
fun testLaunchName() = runTest {
assertName("coroutine#1")
- launch(coroutineContext + CoroutineName("TEST")) {
+ launch(CoroutineName("TEST")) {
assertName("TEST#2")
yield()
assertName("TEST#2")
diff --git a/core/kotlinx-coroutines-core/test/DefaultExecutorStressTest.kt b/core/kotlinx-coroutines-core/test/DefaultExecutorStressTest.kt
index f0cb3ec..ba2b804 100644
--- a/core/kotlinx-coroutines-core/test/DefaultExecutorStressTest.kt
+++ b/core/kotlinx-coroutines-core/test/DefaultExecutorStressTest.kt
@@ -6,36 +6,34 @@
import org.junit.*
import java.util.concurrent.*
-import kotlin.coroutines.experimental.*
class DefaultExecutorStressTest : TestBase() {
-
@Test
fun testDelay() = runTest {
val iterations = 100_000 * stressTestMultiplier
-
- val ctx = DefaultExecutor + coroutineContext
- expect(1)
- var expected = 1
- repeat(iterations) {
- expect(++expected)
- val deferred = async(ctx) {
+ withContext(DefaultExecutor) {
+ expect(1)
+ var expected = 1
+ repeat(iterations) {
expect(++expected)
- val largeArray = IntArray(10_000) { it }
- delay(Long.MAX_VALUE, TimeUnit.NANOSECONDS)
- println(largeArray) // consume to avoid DCE, actually unreachable
+ val deferred = async {
+ expect(++expected)
+ val largeArray = IntArray(10_000) { it }
+ delay(Long.MAX_VALUE, TimeUnit.NANOSECONDS)
+ println(largeArray) // consume to avoid DCE, actually unreachable
+ }
+
+ expect(++expected)
+ yield()
+ deferred.cancel()
+ try {
+ deferred.await()
+ } catch (e: JobCancellationException) {
+ expect(++expected)
+ }
}
- expect(++expected)
- yield()
- deferred.cancel()
- try {
- deferred.await()
- } catch (e: JobCancellationException) {
- expect(++expected)
- }
}
-
finish(2 + iterations * 4)
}
}
diff --git a/core/kotlinx-coroutines-core/test/DelayJvmTest.kt b/core/kotlinx-coroutines-core/test/DelayJvmTest.kt
index c6dcd9f..f171281 100644
--- a/core/kotlinx-coroutines-core/test/DelayJvmTest.kt
+++ b/core/kotlinx-coroutines-core/test/DelayJvmTest.kt
@@ -4,11 +4,10 @@
package kotlinx.coroutines.experimental
-import org.hamcrest.MatcherAssert.assertThat
-import org.hamcrest.core.IsEqual
-import org.junit.Test
-import java.util.concurrent.Executor
-import java.util.concurrent.Executors
+import org.hamcrest.MatcherAssert.*
+import org.hamcrest.core.*
+import org.junit.*
+import java.util.concurrent.*
import kotlin.coroutines.experimental.*
class DelayJvmTest : TestBase() {
@@ -45,7 +44,7 @@
@Test
fun testNegativeDelay() = runBlocking {
expect(1)
- val job = async(coroutineContext) {
+ val job = async {
expect(3)
delay(0)
expect(4)
diff --git a/core/kotlinx-coroutines-core/test/ThreadLocalTest.kt b/core/kotlinx-coroutines-core/test/ThreadLocalTest.kt
index cd474cf..46b2ace 100644
--- a/core/kotlinx-coroutines-core/test/ThreadLocalTest.kt
+++ b/core/kotlinx-coroutines-core/test/ThreadLocalTest.kt
@@ -87,7 +87,7 @@
assertEquals(1, intThreadLocal.get())
- val deferred = GlobalScope.async(coroutineContext + intThreadLocal.asContextElement(53)) {
+ val deferred = async(intThreadLocal.asContextElement(53)) {
assertEquals(53, intThreadLocal.get())
}
@@ -120,7 +120,7 @@
assertEquals("ctx", stringThreadLocal.get())
}
- val deferred = async(coroutineContext + stringThreadLocal.asContextElement("async")) {
+ val deferred = async(stringThreadLocal.asContextElement("async")) {
assertEquals("async", stringThreadLocal.get())
}
@@ -153,7 +153,7 @@
++myCounterLocal.get().cnt
}
- val deferred = async(coroutineContext + myCounterLocal.asContextElement(Counter(31))) {
+ val deferred = async(myCounterLocal.asContextElement(Counter(31))) {
assertEquals(31, myCounterLocal.get().cnt)
++myCounterLocal.get().cnt
}
diff --git a/core/kotlinx-coroutines-core/test/WithContextCancellationStressTest.kt b/core/kotlinx-coroutines-core/test/WithContextCancellationStressTest.kt
index 9c42298..329d167 100644
--- a/core/kotlinx-coroutines-core/test/WithContextCancellationStressTest.kt
+++ b/core/kotlinx-coroutines-core/test/WithContextCancellationStressTest.kt
@@ -30,19 +30,20 @@
repeat(iterations) {
val barrier = CyclicBarrier(4)
- val jobWithContext = async(pool) {
+ val ctx = pool + NonCancellable
+ val jobWithContext = async(ctx) {
withContext(wrapperDispatcher(coroutineContext), start = CoroutineStart.ATOMIC) {
barrier.await()
throw IOException()
}
}
- val cancellerJob = async(pool) {
+ val cancellerJob = async(ctx) {
barrier.await()
jobWithContext.cancel(ArithmeticException())
}
- val cancellerJob2 = async(pool) {
+ val cancellerJob2 = async(ctx) {
barrier.await()
jobWithContext.cancel(ArrayIndexOutOfBoundsException())
}
diff --git a/core/kotlinx-coroutines-core/test/channels/ActorTest.kt b/core/kotlinx-coroutines-core/test/channels/ActorTest.kt
index 1132858..70aa73f 100644
--- a/core/kotlinx-coroutines-core/test/channels/ActorTest.kt
+++ b/core/kotlinx-coroutines-core/test/channels/ActorTest.kt
@@ -110,7 +110,7 @@
@Test
fun testCancelEnclosingJob() = runTest {
val job = async {
- actor<Int>(coroutineContext, capacity) {
+ actor<Int>(capacity = capacity) {
expect(1)
channel.receiveOrNull()
expectUnreached()
@@ -154,7 +154,7 @@
fun testChildJob() = runTest {
val parent = Job()
actor<Int>(parent) {
- launch(coroutineContext) {
+ launch {
try {
delay(Long.MAX_VALUE)
} finally {
diff --git a/core/kotlinx-coroutines-core/test/channels/BroadcastChannelMultiReceiveStressTest.kt b/core/kotlinx-coroutines-core/test/channels/BroadcastChannelMultiReceiveStressTest.kt
index 7f8f081..f234d04 100644
--- a/core/kotlinx-coroutines-core/test/channels/BroadcastChannelMultiReceiveStressTest.kt
+++ b/core/kotlinx-coroutines-core/test/channels/BroadcastChannelMultiReceiveStressTest.kt
@@ -11,7 +11,6 @@
import org.junit.runner.*
import org.junit.runners.*
import java.util.concurrent.atomic.*
-import kotlin.coroutines.experimental.*
/**
* Tests delivery of events to multiple broadcast channel subscribers.
@@ -46,9 +45,8 @@
@Test
fun testStress() = runBlocking {
println("--- BroadcastChannelMultiReceiveStressTest $kind with nReceivers=$nReceivers")
- val ctx = pool + coroutineContext[Job]!!
val sender =
- launch(context = ctx + CoroutineName("Sender")) {
+ launch(pool + CoroutineName("Sender")) {
var i = 0L
while (isActive) {
broadcast.send(++i)
@@ -65,7 +63,7 @@
val receiverIndex = receivers.size
val name = "Receiver$receiverIndex"
println("Launching $name")
- receivers += launch(ctx + CoroutineName(name)) {
+ receivers += launch(pool + CoroutineName(name)) {
val channel = broadcast.openSubscription()
when (receiverIndex % 5) {
0 -> doReceive(channel, receiverIndex)
diff --git a/core/kotlinx-coroutines-core/test/channels/BroadcastChannelSubStressTest.kt b/core/kotlinx-coroutines-core/test/channels/BroadcastChannelSubStressTest.kt
index ca264c7..dbfd04e 100644
--- a/core/kotlinx-coroutines-core/test/channels/BroadcastChannelSubStressTest.kt
+++ b/core/kotlinx-coroutines-core/test/channels/BroadcastChannelSubStressTest.kt
@@ -10,7 +10,6 @@
import org.junit.runner.*
import org.junit.runners.*
import java.util.concurrent.atomic.*
-import kotlin.coroutines.experimental.*
/**
* Creates a broadcast channel and repeatedly opens new subscription, receives event, closes it,
@@ -37,15 +36,14 @@
@Test
fun testStress() = runBlocking {
println("--- BroadcastChannelSubStressTest $kind")
- val ctx = coroutineContext + Dispatchers.Default
val sender =
- launch(context = ctx + CoroutineName("Sender")) {
+ launch(context = Dispatchers.Default + CoroutineName("Sender")) {
while (isActive) {
broadcast.send(sentTotal.incrementAndGet())
}
}
val receiver =
- launch(context = ctx + CoroutineName("Receiver")) {
+ launch(context = Dispatchers.Default + CoroutineName("Receiver")) {
var last = -1L
while (isActive) {
val channel = broadcast.openSubscription()
diff --git a/core/kotlinx-coroutines-core/test/channels/ChannelSendReceiveStressTest.kt b/core/kotlinx-coroutines-core/test/channels/ChannelSendReceiveStressTest.kt
index 4330798..57e69ec 100644
--- a/core/kotlinx-coroutines-core/test/channels/ChannelSendReceiveStressTest.kt
+++ b/core/kotlinx-coroutines-core/test/channels/ChannelSendReceiveStressTest.kt
@@ -11,7 +11,6 @@
import org.junit.runner.*
import org.junit.runners.*
import java.util.concurrent.atomic.*
-import kotlin.coroutines.experimental.*
@RunWith(Parameterized::class)
class ChannelSendReceiveStressTest(
@@ -70,7 +69,7 @@
}
}
// print progress
- val progressJob = launch(coroutineContext) {
+ val progressJob = launch {
var seconds = 0
while (true) {
delay(1000)
diff --git a/core/kotlinx-coroutines-core/test/channels/ChannelsConsumeTest.kt b/core/kotlinx-coroutines-core/test/channels/ChannelsConsumeTest.kt
index 4643910..aa58e7a 100644
--- a/core/kotlinx-coroutines-core/test/channels/ChannelsConsumeTest.kt
+++ b/core/kotlinx-coroutines-core/test/channels/ChannelsConsumeTest.kt
@@ -5,7 +5,6 @@
package kotlinx.coroutines.experimental.channels
import kotlinx.coroutines.experimental.*
-import kotlin.coroutines.experimental.*
import kotlin.test.*
/**
@@ -15,7 +14,7 @@
private val sourceList = (1..10).toList()
// test source with numbers 1..10
- private fun testSource(context: CoroutineContext) = CoroutineScope(context).produce {
+ private fun CoroutineScope.testSource() = produce {
for (i in sourceList) {
send(i)
}
@@ -239,29 +238,29 @@
@Test
fun testDrop() {
- checkTransform(sourceList.drop(3)) { ctx ->
- drop(3, ctx)
+ checkTransform(sourceList.drop(3)) {
+ drop(3)
}
}
@Test
fun testDropWhile() {
- checkTransform(sourceList.dropWhile { it < 4}) { ctx ->
- dropWhile(ctx) { it < 4 }
+ checkTransform(sourceList.dropWhile { it < 4}) {
+ dropWhile { it < 4 }
}
}
@Test
fun testFilter() {
- checkTransform(sourceList.filter { it % 2 == 0 }) { ctx ->
- filter(ctx) { it % 2 == 0 }
+ checkTransform(sourceList.filter { it % 2 == 0 }) {
+ filter { it % 2 == 0 }
}
}
@Test
fun testFilterIndexed() {
- checkTransform(sourceList.filterIndexed { index, _ -> index % 2 == 0 }) { ctx ->
- filterIndexed(ctx) { index, _ -> index % 2 == 0 }
+ checkTransform(sourceList.filterIndexed { index, _ -> index % 2 == 0 }) {
+ filterIndexed { index, _ -> index % 2 == 0 }
}
}
@@ -287,8 +286,8 @@
@Test
fun testFilterNot() {
- checkTransform(sourceList.filterNot { it % 2 == 0 }) { ctx ->
- filterNot(ctx) { it % 2 == 0 }
+ checkTransform(sourceList.filterNot { it % 2 == 0 }) {
+ filterNot { it % 2 == 0 }
}
}
@@ -354,15 +353,15 @@
@Test
fun testTake() {
- checkTransform(sourceList.take(3)) { ctx ->
- take(3, ctx)
+ checkTransform(sourceList.take(3)) {
+ take(3)
}
}
@Test
fun testTakeWhile() {
- checkTransform(sourceList.takeWhile { it < 4 }) { ctx ->
- takeWhile(ctx) { it < 4 }
+ checkTransform(sourceList.takeWhile { it < 4 }) {
+ takeWhile { it < 4 }
}
}
@@ -477,8 +476,8 @@
@Test
fun testFlatMap() {
- checkTransform(sourceList.flatMap { listOf("A$it", "B$it") }) { ctx ->
- flatMap(ctx) {
+ checkTransform(sourceList.flatMap { listOf("A$it", "B$it") }) {
+ flatMap {
GlobalScope.produce {
send("A$it")
send("B$it")
@@ -523,22 +522,22 @@
@Test
fun testMap() {
- checkTransform(sourceList.map { it.toString() }) { ctx ->
- map(ctx) { it.toString() }
+ checkTransform(sourceList.map { it.toString() }) {
+ map { it.toString() }
}
}
@Test
fun testMapIndexed() {
- checkTransform(sourceList.mapIndexed { index, v -> "$index$v" }) { ctx ->
- mapIndexed(ctx) { index, v -> "$index$v" }
+ checkTransform(sourceList.mapIndexed { index, v -> "$index$v" }) {
+ mapIndexed { index, v -> "$index$v" }
}
}
@Test
fun testMapIndexedNotNull() {
- checkTransform(sourceList.mapIndexedNotNull { index, v -> "$index$v".takeIf { v % 2 == 0 } }) { ctx ->
- mapIndexedNotNull(ctx) { index, v -> "$index$v".takeIf { v % 2 == 0 } }
+ checkTransform(sourceList.mapIndexedNotNull { index, v -> "$index$v".takeIf { v % 2 == 0 } }) {
+ mapIndexedNotNull { index, v -> "$index$v".takeIf { v % 2 == 0 } }
}
}
@@ -584,8 +583,8 @@
@Test
fun testMapNotNull() {
- checkTransform(sourceList.mapNotNull { (it + 3).takeIf { it % 2 == 0 } }) { ctx ->
- mapNotNull(ctx) { (it + 3).takeIf { it % 2 == 0 } }
+ checkTransform(sourceList.mapNotNull { (it + 3).takeIf { it % 2 == 0 } }) {
+ mapNotNull { (it + 3).takeIf { it % 2 == 0 } }
}
}
@@ -631,15 +630,15 @@
@Test
fun testWithIndex() {
- checkTransform(sourceList.withIndex().toList()) { ctx ->
- withIndex(ctx)
+ checkTransform(sourceList.withIndex().toList()) {
+ withIndex()
}
}
@Test
fun testDistinctBy() {
- checkTransform(sourceList.distinctBy { it / 2 }) { ctx ->
- distinctBy(ctx) { it / 2 }
+ checkTransform(sourceList.distinctBy { it / 2 }) {
+ distinctBy { it / 2 }
}
}
@@ -798,11 +797,15 @@
@Test
fun testZip() {
val expect = sourceList.zip(sourceList) { a, b -> a + 2 * b }
- checkTransform(expect) { ctx ->
- zip(testSource(ctx), ctx) { a, b -> a + 2*b }
+ checkTransform(expect) {
+ currentScope {
+ zip(testSource()) { a, b -> a + 2*b }
+ }
}
- checkTransform(expect) { ctx ->
- testSource(ctx).zip(this, ctx) { a, b -> a + 2*b }
+ checkTransform(expect) {
+ currentScope {
+ testSource().zip(this@checkTransform) { a, b -> a + 2*b }
+ }
}
}
@@ -821,7 +824,7 @@
terminal: suspend ReceiveChannel<Int>.() -> Unit
) {
val src = runBlocking {
- val src = testSource(coroutineContext)
+ val src = testSource()
try {
// terminal operation
terminal(src)
@@ -841,9 +844,9 @@
terminal: suspend ReceiveChannel<Int>.() -> Unit
) {
val src = runBlocking {
- val src = testSource(coroutineContext)
+ val src = testSource()
// terminal operation in a separate async context started until the first suspension
- val d = async(coroutineContext, start = CoroutineStart.UNDISPATCHED) {
+ val d = async(start = CoroutineStart.UNDISPATCHED) {
terminal(src)
}
// then cancel it
@@ -866,7 +869,7 @@
private fun <R> checkTransform(
expect: List<R>,
- transform: ReceiveChannel<Int>.(CoroutineContext) -> ReceiveChannel<R>
+ transform: suspend ReceiveChannel<Int>.() -> ReceiveChannel<R>
) {
// check for varying number of received elements from the channel
for (nReceive in 0..expect.size) {
@@ -877,12 +880,12 @@
private fun <R> checkTransform(
nReceive: Int,
expect: List<R>,
- transform: ReceiveChannel<Int>.(CoroutineContext) -> ReceiveChannel<R>
+ transform: suspend ReceiveChannel<Int>.() -> ReceiveChannel<R>
) {
val src = runBlocking {
- val src = testSource(coroutineContext)
+ val src = testSource()
// transform
- val res = transform(src, coroutineContext)
+ val res = transform(src)
// receive nReceive elements from the result
repeat(nReceive) { i ->
assertEquals(expect[i], res.receive())
diff --git a/core/kotlinx-coroutines-core/test/channels/ConflatedBroadcastChannelNotifyStressTest.kt b/core/kotlinx-coroutines-core/test/channels/ConflatedBroadcastChannelNotifyStressTest.kt
index bebcd37..3e0729a 100644
--- a/core/kotlinx-coroutines-core/test/channels/ConflatedBroadcastChannelNotifyStressTest.kt
+++ b/core/kotlinx-coroutines-core/test/channels/ConflatedBroadcastChannelNotifyStressTest.kt
@@ -9,7 +9,6 @@
import org.hamcrest.core.*
import org.junit.*
import java.util.concurrent.atomic.*
-import kotlin.coroutines.experimental.*
class ConflatedBroadcastChannelNotifyStressTest : TestBase() {
val nSenders = 2
@@ -55,7 +54,7 @@
}
}
// print progress
- val progressJob = launch(coroutineContext) {
+ val progressJob = launch {
var seconds = 0
while (true) {
delay(1000)
diff --git a/core/kotlinx-coroutines-core/test/channels/ProduceConsumeJvmTest.kt b/core/kotlinx-coroutines-core/test/channels/ProduceConsumeJvmTest.kt
index ac112a3..d1cde33 100644
--- a/core/kotlinx-coroutines-core/test/channels/ProduceConsumeJvmTest.kt
+++ b/core/kotlinx-coroutines-core/test/channels/ProduceConsumeJvmTest.kt
@@ -9,7 +9,6 @@
import org.junit.Assert.*
import org.junit.runner.*
import org.junit.runners.*
-import kotlin.coroutines.experimental.*
@RunWith(Parameterized::class)
class ProduceConsumeJvmTest(
@@ -30,7 +29,7 @@
@Test
fun testProducer() = runTest {
var sentAll = false
- val producer = produce(coroutineContext, capacity = capacity) {
+ val producer = produce(capacity = capacity) {
for (i in 1..number) {
send(i)
}
@@ -47,7 +46,7 @@
@Test
fun testActor() = runTest {
val received = CompletableDeferred<Int>()
- val actor = actor<Int>(coroutineContext, capacity = capacity) {
+ val actor = actor<Int>(capacity = capacity) {
var n = 0
for(i in channel) {
n++
diff --git a/core/kotlinx-coroutines-core/test/channels/RandevouzChannelStressTest.kt b/core/kotlinx-coroutines-core/test/channels/RandevouzChannelStressTest.kt
index f6b0b1a..1fc2c8f 100644
--- a/core/kotlinx-coroutines-core/test/channels/RandevouzChannelStressTest.kt
+++ b/core/kotlinx-coroutines-core/test/channels/RandevouzChannelStressTest.kt
@@ -6,7 +6,6 @@
import kotlinx.coroutines.experimental.*
import org.junit.*
-import kotlin.coroutines.experimental.*
class RandevouzChannelStressTest : TestBase() {
@@ -14,11 +13,11 @@
fun testStress() = runTest {
val n = 100_000 * stressTestMultiplier
val q = RendezvousChannel<Int>()
- val sender = launch(coroutineContext) {
+ val sender = launch {
for (i in 1..n) q.send(i)
expect(2)
}
- val receiver = launch(coroutineContext) {
+ val receiver = launch {
for (i in 1..n) check(q.receive() == i)
expect(3)
}
diff --git a/core/kotlinx-coroutines-core/test/channels/SendReceiveJvmStressTest.kt b/core/kotlinx-coroutines-core/test/channels/SendReceiveJvmStressTest.kt
index 408c824..8c5b080 100644
--- a/core/kotlinx-coroutines-core/test/channels/SendReceiveJvmStressTest.kt
+++ b/core/kotlinx-coroutines-core/test/channels/SendReceiveJvmStressTest.kt
@@ -7,7 +7,6 @@
import kotlinx.coroutines.experimental.*
import org.junit.runner.*
import org.junit.runners.*
-import kotlin.coroutines.experimental.*
import kotlin.test.*
@RunWith(Parameterized::class)
@@ -28,13 +27,13 @@
@Test
fun testStress() = runTest {
val n = 100_000 * stressTestMultiplier
- val sender = launch(coroutineContext) {
+ val sender = launch {
for (i in 1..n) {
channel.send(i)
}
expect(2)
}
- val receiver = launch(coroutineContext) {
+ val receiver = launch {
for (i in 1..n) {
val next = channel.receive()
check(next == i)
diff --git a/core/kotlinx-coroutines-core/test/exceptions/JobBasicCancellationTest.kt b/core/kotlinx-coroutines-core/test/exceptions/JobBasicCancellationTest.kt
index 4f82015..08bbb98 100644
--- a/core/kotlinx-coroutines-core/test/exceptions/JobBasicCancellationTest.kt
+++ b/core/kotlinx-coroutines-core/test/exceptions/JobBasicCancellationTest.kt
@@ -7,7 +7,6 @@
import kotlinx.coroutines.experimental.*
import org.junit.Test
import java.io.*
-import kotlin.coroutines.experimental.*
import kotlin.test.*
/*
@@ -19,9 +18,9 @@
@Test
fun testJobCancelChild() = runTest {
- val parent = launch(coroutineContext) {
+ val parent = launch {
expect(1)
- val child = launch(coroutineContext) {
+ val child = launch {
expect(2)
}
@@ -38,9 +37,9 @@
@Test
fun testJobCancelChildAtomic() = runTest {
- val parent = launch(coroutineContext) {
+ val parent = launch {
expect(1)
- val child = launch(coroutineContext, CoroutineStart.ATOMIC) {
+ val child = launch(start = CoroutineStart.ATOMIC) {
expect(3)
}
@@ -59,9 +58,9 @@
@Test
fun testAsyncCancelChild() = runTest {
- val parent = async(coroutineContext) {
+ val parent = async {
expect(1)
- val child = async(coroutineContext) {
+ val child = async {
expect(2)
}
@@ -78,9 +77,9 @@
@Test
fun testAsyncCancelChildAtomic() = runTest {
- val parent = async(coroutineContext) {
+ val parent = async {
expect(1)
- val child = async(coroutineContext, CoroutineStart.ATOMIC) {
+ val child = async(start = CoroutineStart.ATOMIC) {
expect(3)
}
@@ -96,8 +95,8 @@
@Test
fun testNestedAsyncFailure() = runTest {
- val deferred = async(coroutineContext) {
- val nested = async(coroutineContext) {
+ val deferred = async {
+ val nested = async {
expect(3)
throw IOException()
}
@@ -118,7 +117,7 @@
@Test
fun testCancelJobImpl() = runTest {
- val parent = launch(coroutineContext) {
+ val parent = launch {
expect(1)
val child = Job(coroutineContext[Job])
expect(2)
@@ -134,7 +133,7 @@
@Test
fun cancelCompletableDeferred() = runTest {
- val parent = launch(coroutineContext) {
+ val parent = launch {
expect(1)
val child = CompletableDeferred<Unit>(coroutineContext[Job])
expect(2)
diff --git a/core/kotlinx-coroutines-core/test/exceptions/JobExceptionsStressTest.kt b/core/kotlinx-coroutines-core/test/exceptions/JobExceptionsStressTest.kt
index f47cd13..760cc05 100644
--- a/core/kotlinx-coroutines-core/test/exceptions/JobExceptionsStressTest.kt
+++ b/core/kotlinx-coroutines-core/test/exceptions/JobExceptionsStressTest.kt
@@ -30,26 +30,21 @@
repeat(1000 * stressTestMultiplier) {
val exception = runBlock(executor) {
val barrier = CyclicBarrier(4)
- val job = GlobalScope.launch(coroutineContext.minusKey(Job)) {
-
- launch(coroutineContext) {
+ val job = launch(NonCancellable) {
+ launch(start = CoroutineStart.ATOMIC) {
barrier.await()
throw ArithmeticException()
}
-
- launch(coroutineContext) {
+ launch(start = CoroutineStart.ATOMIC) {
barrier.await()
throw IOException()
}
-
- launch(coroutineContext) {
+ launch(start = CoroutineStart.ATOMIC) {
barrier.await()
throw IllegalArgumentException()
}
-
delay(Long.MAX_VALUE)
}
-
barrier.await()
job.join()
}
diff --git a/core/kotlinx-coroutines-core/test/exceptions/JobNestedExceptionsTest.kt b/core/kotlinx-coroutines-core/test/exceptions/JobNestedExceptionsTest.kt
index bc7cd76..5affae1 100644
--- a/core/kotlinx-coroutines-core/test/exceptions/JobNestedExceptionsTest.kt
+++ b/core/kotlinx-coroutines-core/test/exceptions/JobNestedExceptionsTest.kt
@@ -68,10 +68,10 @@
fun testNestedAtomicThrow() {
val exception = runBlock {
expect(1)
- val job = GlobalScope.launch(coroutineContext.minusKey(Job), CoroutineStart.ATOMIC) {
+ val job = launch(NonCancellable, start = CoroutineStart.ATOMIC) {
expect(2)
- GlobalScope.launch(coroutineContext, CoroutineStart.ATOMIC) {
+ launch(start = CoroutineStart.ATOMIC) {
expect(3)
throw IOException()
}
@@ -91,12 +91,11 @@
fun testChildThrowsDuringCompletion() {
val exceptions = runBlockForMultipleExceptions {
expect(1)
- val job = GlobalScope.launch(coroutineContext.minusKey(Job), CoroutineStart.ATOMIC) {
+ val job = launch(NonCancellable, start = CoroutineStart.ATOMIC) {
expect(2)
-
- GlobalScope.launch(coroutineContext, CoroutineStart.ATOMIC) {
+ launch(start = CoroutineStart.ATOMIC) {
expect(3)
- GlobalScope.launch(coroutineContext, CoroutineStart.ATOMIC) {
+ launch(start = CoroutineStart.ATOMIC) {
// This child attaches to the parent and throws after parent completion
expect(4)
throw NullPointerException()
diff --git a/core/kotlinx-coroutines-core/test/scheduling/CoroutineDispatcherTest.kt b/core/kotlinx-coroutines-core/test/scheduling/CoroutineDispatcherTest.kt
index c599e33..0f2b083 100644
--- a/core/kotlinx-coroutines-core/test/scheduling/CoroutineDispatcherTest.kt
+++ b/core/kotlinx-coroutines-core/test/scheduling/CoroutineDispatcherTest.kt
@@ -8,7 +8,6 @@
import org.junit.*
import org.junit.Test
import java.util.concurrent.atomic.*
-import kotlin.coroutines.experimental.*
import kotlin.test.*
class CoroutineDispatcherTest : SchedulerTestBase() {
@@ -24,7 +23,7 @@
withContext(dispatcher) {
require(Thread.currentThread() is CoroutineScheduler.Worker)
expect(2)
- val job = async(coroutineContext) {
+ val job = async {
expect(3)
delay(10)
expect(4)
diff --git a/core/kotlinx-coroutines-core/test/selects/SelectPhilosophersStressTest.kt b/core/kotlinx-coroutines-core/test/selects/SelectPhilosophersStressTest.kt
index a15d04d..f49da71 100644
--- a/core/kotlinx-coroutines-core/test/selects/SelectPhilosophersStressTest.kt
+++ b/core/kotlinx-coroutines-core/test/selects/SelectPhilosophersStressTest.kt
@@ -8,7 +8,6 @@
import kotlinx.coroutines.experimental.sync.*
import org.junit.*
import org.junit.Assert.*
-import kotlin.coroutines.experimental.*
class SelectPhilosophersStressTest : TestBase() {
val TEST_DURATION = 3000L * stressTestMultiplier
@@ -52,7 +51,7 @@
eatsCount
}
}
- val debugJob = launch(coroutineContext) {
+ val debugJob = launch {
delay(3 * TEST_DURATION)
println("Test is failing. Lock states are:")
forks.withIndex().forEach { (id, mutex) -> println("$id: $mutex") }