Skip to content

Commit

Permalink
Make isStressTest and the related properties top-level
Browse files Browse the repository at this point in the history
  • Loading branch information
ndkoval authored and elizarov committed Sep 30, 2019
1 parent 216828a commit 8fa07b5
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 27 deletions.
6 changes: 3 additions & 3 deletions kotlinx-coroutines-core/common/test/TestBase.common.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import kotlinx.coroutines.flow.*
import kotlin.coroutines.*
import kotlin.test.*

public expect open class TestBase constructor() {
public val isStressTest: Boolean
public val stressTestMultiplier: Int
public expect val isStressTest: Boolean
public expect val stressTestMultiplier: Int

public expect open class TestBase constructor() {
public fun error(message: Any, cause: Throwable? = null): Nothing
public fun expect(index: Int)
public fun expectUnreached()
Expand Down
6 changes: 3 additions & 3 deletions kotlinx-coroutines-core/js/test/TestBase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ package kotlinx.coroutines

import kotlin.js.*

public actual open class TestBase actual constructor() {
public actual val isStressTest: Boolean = false
public actual val stressTestMultiplier: Int = 1
public actual val isStressTest: Boolean = false
public actual val stressTestMultiplier: Int = 1

public actual open class TestBase actual constructor() {
private var actionIndex = 0
private var finished = false
private var error: Throwable? = null
Expand Down
24 changes: 12 additions & 12 deletions kotlinx-coroutines-core/jvm/test/TestBase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@ import kotlin.test.*

private val VERBOSE = systemProp("test.verbose", false)

/**
* Is `true` when running in a nightly stress test mode.
*/
public actual val isStressTest = System.getProperty("stressTest")?.toBoolean() ?: false

public val stressTestMultiplierSqrt = if (isStressTest) 5 else 1

/**
* Multiply various constants in stress tests by this factor, so that they run longer during nightly stress test.
*/
public actual val stressTestMultiplier = stressTestMultiplierSqrt * stressTestMultiplierSqrt

/**
* Base class for tests, so that tests for predictable scheduling of actions in multiple coroutines sharing a single
* thread can be written. Use it like this:
Expand All @@ -34,18 +46,6 @@ private val VERBOSE = systemProp("test.verbose", false)
* ```
*/
public actual open class TestBase actual constructor() {
/**
* Is `true` when running in a nightly stress test mode.
*/
public actual val isStressTest = System.getProperty("stressTest")?.toBoolean() ?: false

public val stressTestMultiplierSqrt = if (isStressTest) 5 else 1

/**
* Multiply various constants in stress tests by this factor, so that they run longer during nightly stress test.
*/
public actual val stressTestMultiplier = stressTestMultiplierSqrt * stressTestMultiplierSqrt

private var actionIndex = AtomicInteger()
private var finished = AtomicBoolean()
private var error = AtomicReference<Throwable>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
package kotlinx.coroutines.internal

import kotlinx.atomicfu.LockFreedomTestEnvironment
import kotlinx.coroutines.TestBase
import kotlinx.coroutines.stressTestMultiplier
import org.junit.Assert.*
import org.junit.Test
import java.util.*
Expand All @@ -16,7 +16,7 @@ import java.util.concurrent.atomic.AtomicReference
* This stress test has 4 threads adding randomly to the list and them immediately undoing
* this addition by remove, and 4 threads trying to remove nodes from two lists simultaneously (atomically).
*/
class LockFreeLinkedListAtomicLFStressTest : TestBase() {
class LockFreeLinkedListAtomicLFStressTest {
private val env = LockFreedomTestEnvironment("LockFreeLinkedListAtomicLFStressTest")

data class IntNode(val i: Int) : LockFreeLinkedListNode()
Expand Down
7 changes: 3 additions & 4 deletions kotlinx-coroutines-core/jvm/test/internal/SegmentQueueTest.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package kotlinx.coroutines.internal

import kotlinx.coroutines.TestBase
import kotlinx.coroutines.stressTestMultiplier
import org.junit.Test
import java.util.*
import java.util.concurrent.CyclicBarrier
Expand All @@ -9,12 +9,11 @@ import kotlin.concurrent.thread
import kotlin.random.Random
import kotlin.test.assertEquals

class SegmentQueueTest : TestBase() {

class SegmentQueueTest {
@Test
fun simpleTest() {
val q = SegmentBasedQueue<Int>()
assertEquals( 1, q.numberOfSegments)
assertEquals(1, q.numberOfSegments)
assertEquals(null, q.dequeue())
q.enqueue(1)
assertEquals(1, q.numberOfSegments)
Expand Down
6 changes: 3 additions & 3 deletions kotlinx-coroutines-core/native/test/TestBase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

package kotlinx.coroutines

public actual open class TestBase actual constructor() {
public actual val isStressTest: Boolean = false
public actual val stressTestMultiplier: Int = 1
public actual val isStressTest: Boolean = false
public actual val stressTestMultiplier: Int = 1

public actual open class TestBase actual constructor() {
private var actionIndex = 0
private var finished = false
private var error: Throwable? = null
Expand Down

0 comments on commit 8fa07b5

Please sign in to comment.