Skip to content

Commit 4e29357

Browse files
Disable tests with real source of the time on Java's Windows to preve… (#3516)
* Disable tests with the real source of the time on Java's Windows to prevent flakiness We still want to test real code, not virtualized mocked clocks, but Windows itself is virtualized on our TeamCity, making Java's parker resolution really low and unstable for such tests Co-authored-by: dkhalanskyjb <[email protected]>
1 parent 6c9d358 commit 4e29357

File tree

8 files changed

+18
-32
lines changed

8 files changed

+18
-32
lines changed

kotlinx-coroutines-core/common/test/JobTest.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,11 @@ class JobTest : TestBase() {
103103
}
104104
assertTrue(job.isActive)
105105
for (i in 0 until n) assertEquals(0, fireCount[i])
106-
val tryCancel = Try { job.cancel() }
106+
val cancelResult = runCatching { job.cancel() }
107107
assertTrue(!job.isActive)
108108
for (i in 0 until n) assertEquals(1, fireCount[i])
109-
assertTrue(tryCancel.exception is CompletionHandlerException)
110-
assertTrue(tryCancel.exception!!.cause is TestException)
109+
assertTrue(cancelResult.exceptionOrNull() is CompletionHandlerException)
110+
assertTrue(cancelResult.exceptionOrNull()!!.cause is TestException)
111111
}
112112

113113
@Test

kotlinx-coroutines-core/common/test/TestBase.common.kt

+2
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,5 @@ class BadClass {
104104
override fun hashCode(): Int = error("hashCode")
105105
override fun toString(): String = error("toString")
106106
}
107+
108+
public expect val isJavaAndWindows: Boolean

kotlinx-coroutines-core/common/test/Try.kt

-29
This file was deleted.

kotlinx-coroutines-core/common/test/WithTimeoutOrNullDurationTest.kt

+1
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ class WithTimeoutOrNullDurationTest : TestBase() {
131131

132132
@Test
133133
fun testOuterTimeout() = runTest {
134+
if (isJavaAndWindows) return@runTest
134135
var counter = 0
135136
val result = withTimeoutOrNull(320.milliseconds) {
136137
while (true) {

kotlinx-coroutines-core/common/test/WithTimeoutOrNullTest.kt

+1
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ class WithTimeoutOrNullTest : TestBase() {
128128

129129
@Test
130130
fun testOuterTimeout() = runTest {
131+
if (isJavaAndWindows) return@runTest
131132
var counter = 0
132133
val result = withTimeoutOrNull(320) {
133134
while (true) {

kotlinx-coroutines-core/js/test/TestBase.kt

+2
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,5 @@ public actual open class TestBase actual constructor() {
138138

139139
private fun <T> Promise<T>.finally(block: () -> Unit): Promise<T> =
140140
then(onFulfilled = { value -> block(); value }, onRejected = { ex -> block(); throw ex })
141+
142+
public actual val isJavaAndWindows: Boolean get() = false

kotlinx-coroutines-core/jvm/test/TestBase.kt

+7
Original file line numberDiff line numberDiff line change
@@ -254,3 +254,10 @@ public actual open class TestBase(private var disableOutCheck: Boolean) {
254254

255255
protected suspend fun currentDispatcher() = coroutineContext[ContinuationInterceptor]!!
256256
}
257+
258+
/*
259+
* We ignore tests that test **real** non-virtualized tests with time on Windows, because
260+
* our CI Windows is virtualized itself (oh, the irony) and its clock resolution is dozens of ms,
261+
* which makes such tests flaky.
262+
*/
263+
public actual val isJavaAndWindows: Boolean = System.getProperty("os.name")!!.contains("Windows")

kotlinx-coroutines-core/native/test/TestBase.kt

+2
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,5 @@ public actual open class TestBase actual constructor() {
107107
error("Too few unhandled exceptions $exCount, expected ${unhandled.size}")
108108
}
109109
}
110+
111+
public actual val isJavaAndWindows: Boolean get() = false

0 commit comments

Comments
 (0)