1 /* 2 * Copyright 2016-2022 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 */ 4 5 package kotlinx.coroutines 6 7 import kotlin.test.* 8 9 class LimitedParallelismSharedTest : TestBase() { 10 11 @Test <lambda>null12 fun testLimitedDefault() = runTest { 13 // Test that evaluates the very basic completion of tasks in limited dispatcher 14 // for all supported platforms. 15 // For more specific and concurrent tests, see 'concurrent' package. 16 val view = Dispatchers.Default.limitedParallelism(1) 17 val view2 = Dispatchers.Default.limitedParallelism(1) 18 val j1 = launch(view) { 19 while (true) { 20 yield() 21 } 22 } 23 val j2 = launch(view2) { j1.cancel() } 24 joinAll(j1, j2) 25 } 26 27 @Test testParallelismSpecnull28 fun testParallelismSpec() { 29 assertFailsWith<IllegalArgumentException> { Dispatchers.Default.limitedParallelism(0) } 30 assertFailsWith<IllegalArgumentException> { Dispatchers.Default.limitedParallelism(-1) } 31 assertFailsWith<IllegalArgumentException> { Dispatchers.Default.limitedParallelism(Int.MIN_VALUE) } 32 Dispatchers.Default.limitedParallelism(Int.MAX_VALUE) 33 } 34 } 35