Skip to content

Commit

Permalink
Less iterations in SelectChannelStressTest for native platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
mvicsokolova authored and qwwdfsad committed Aug 5, 2021
1 parent f7cfda4 commit 16b64a8
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 12 deletions.
2 changes: 2 additions & 0 deletions kotlinx-coroutines-core/common/test/TestBase.common.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public expect val stressTestMultiplierSqrt: Int
@Suppress("NO_ACTUAL_FOR_EXPECT")
public expect class TestResult

public expect val isNative: Boolean

public expect open class TestBase constructor() {
/*
* In common tests we emulate parameterized tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,61 +11,60 @@ import kotlin.test.*

class SelectChannelStressTest: TestBase() {

// Running less iterations on native platforms because of some performance regression
private val iterations = (if (isNative) 1_000 else 1_000_000) * stressTestMultiplier

@Test
fun testSelectSendResourceCleanupArrayChannel() = runTest {
val channel = Channel<Int>(1)
val n = 10_000_000 * stressTestMultiplier
expect(1)
channel.send(-1) // fill the buffer, so all subsequent sends cannot proceed
repeat(n) { i ->
repeat(iterations) { i ->
select {
channel.onSend(i) { expectUnreached() }
default { expect(i + 2) }
}
}
finish(n + 2)
finish(iterations + 2)
}

@Test
fun testSelectReceiveResourceCleanupArrayChannel() = runTest {
val channel = Channel<Int>(1)
val n = 10_000_000 * stressTestMultiplier
expect(1)
repeat(n) { i ->
repeat(iterations) { i ->
select {
channel.onReceive { expectUnreached() }
default { expect(i + 2) }
}
}
finish(n + 2)
finish(iterations + 2)
}

@Test
fun testSelectSendResourceCleanupRendezvousChannel() = runTest {
val channel = Channel<Int>(Channel.RENDEZVOUS)
val n = 1_000_000 * stressTestMultiplier
expect(1)
repeat(n) { i ->
repeat(iterations) { i ->
select {
channel.onSend(i) { expectUnreached() }
default { expect(i + 2) }
}
}
finish(n + 2)
finish(iterations + 2)
}

@Test
fun testSelectReceiveResourceRendezvousChannel() = runTest {
val channel = Channel<Int>(Channel.RENDEZVOUS)
val n = 1_000_000 * stressTestMultiplier
expect(1)
repeat(n) { i ->
repeat(iterations) { i ->
select {
channel.onReceive { expectUnreached() }
default { expect(i + 2) }
}
}
finish(n + 2)
finish(iterations + 2)
}

internal fun <R> SelectBuilder<R>.default(block: suspend () -> R) {
Expand Down
2 changes: 2 additions & 0 deletions kotlinx-coroutines-core/js/test/TestBase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public actual val stressTestMultiplierSqrt: Int = 1
@Suppress("ACTUAL_WITHOUT_EXPECT", "ACTUAL_TYPE_ALIAS_TO_CLASS_WITH_DECLARATION_SITE_VARIANCE")
public actual typealias TestResult = Promise<Unit>

public actual val isNative = false

public actual open class TestBase actual constructor() {
public actual val isBoundByJsTestTimeout = true
private var actionIndex = 0
Expand Down
2 changes: 2 additions & 0 deletions kotlinx-coroutines-core/jvm/test/TestBase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public actual val isStressTest = System.getProperty("stressTest")?.toBoolean() ?

public actual val stressTestMultiplierSqrt = if (isStressTest) 5 else 1

public actual val isNative = false

/**
* Multiply various constants in stress tests by this factor, so that they run longer during nightly stress test.
*/
Expand Down
2 changes: 2 additions & 0 deletions kotlinx-coroutines-core/native/test/TestBase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ public actual val isStressTest: Boolean = false
public actual val stressTestMultiplier: Int = 1
public actual val stressTestMultiplierSqrt: Int = 1

public actual val isNative = true

@Suppress("ACTUAL_WITHOUT_EXPECT")
public actual typealias TestResult = Unit

Expand Down

0 comments on commit 16b64a8

Please sign in to comment.