Skip to content

Commit 0ba63b3

Browse files
committed
Fix flaky tests
1 parent b4db18a commit 0ba63b3

File tree

14 files changed

+35
-17
lines changed

14 files changed

+35
-17
lines changed

karma/chrome_bin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ config.set({
2121
"client": {
2222
captureConsole: true,
2323
"mocha": {
24-
timeout: 10000
24+
timeout: 300000
2525
}
2626
}
2727
});

krpc/krpc-test/build.gradle.kts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,6 @@ tasks.named<Delete>("clean") {
100100
delete(resourcesPath.walk().filter { it.isFile && it.extension == tmpExt }.toList())
101101
}
102102

103-
tasks.withType<KotlinJsTest> {
104-
onlyIf {
105-
// for some reason browser tests don't wait for the test to complete and end immediately
106-
// KRPC-166
107-
!targetName.orEmpty().endsWith("browser")
108-
}
109-
}
110-
111103
tasks.register("moveToGold") {
112104
doLast {
113105
resourcesPath.walk().forEach {

krpc/krpc-test/src/commonMain/kotlin/kotlinx/rpc/krpc/test/KrpcTestService.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,17 @@ interface KrpcTestService {
9494

9595
suspend fun nullableInt(v: Int?): Int?
9696
suspend fun nullableList(v: List<Int>?): List<Int>?
97+
suspend fun nullableEnum(enum: TestEnum?): TestEnum?
9798
fun delayForever(): Flow<Boolean>
9899

99100
suspend fun answerToAnything(arg: String): Int
100101

101102
suspend fun krpc173()
102103

103104
fun unitFlow(): Flow<Unit>
105+
106+
@Serializable
107+
enum class TestEnum {
108+
ENUM_VALUE_1, ENUM_VALUE_2
109+
}
104110
}

krpc/krpc-test/src/commonMain/kotlin/kotlinx/rpc/krpc/test/KrpcTestServiceBackend.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ class KrpcTestServiceBackend : KrpcTestService {
243243

244244
override suspend fun nullableInt(v: Int?): Int? = v
245245
override suspend fun nullableList(v: List<Int>?): List<Int>? = v
246+
override suspend fun nullableEnum(enum: KrpcTestService.TestEnum?): KrpcTestService.TestEnum? = enum
246247

247248
override fun delayForever(): Flow<Boolean> = flow {
248249
emit(true)

krpc/krpc-test/src/commonMain/kotlin/kotlinx/rpc/krpc/test/KrpcTransportTestBase.kt

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ abstract class KrpcTransportTestBase {
324324

325325
@Test
326326
fun RPC_should_be_able_to_receive_100_000_ints_in_reasonable_time() = runTest(timeout = EXTENDED_TIMEOUT) {
327-
val n = 100_000
327+
val n = iterations_100_000
328328
var counter = 0
329329
val last = client.getNInts(n).onEach {
330330
counter++
@@ -336,8 +336,8 @@ abstract class KrpcTransportTestBase {
336336
}
337337

338338
@Test
339-
fun RPC_should_be_able_to_receive_100_000_ints_with_batching_in_reasonable_time() = runTest {
340-
val n = 100_000
339+
fun RPC_should_be_able_to_receive_100_000_ints_with_batching_in_reasonable_time() = runTest(timeout = EXTENDED_TIMEOUT) {
340+
val n = iterations_100_000
341341
assertEquals(client.getNIntsBatched(n).last().last(), n)
342342
}
343343

@@ -400,6 +400,15 @@ abstract class KrpcTransportTestBase {
400400
assertEquals(listOf(1), client.nullableList(listOf(1)))
401401
}
402402

403+
@Test
404+
open fun testNullableEnums() = runTest {
405+
assertNull(client.nullableEnum(null))
406+
assertEquals(
407+
KrpcTestService.TestEnum.ENUM_VALUE_1,
408+
client.nullableEnum(KrpcTestService.TestEnum.ENUM_VALUE_1),
409+
)
410+
}
411+
403412
@Test
404413
fun testServerCallCancellation() = runTest {
405414
val flag: Channel<Boolean> = Channel()
@@ -500,3 +509,4 @@ abstract class KrpcTransportTestBase {
500509
private val EXTENDED_TIMEOUT = if (isJs) 500.seconds else 200.seconds
501510

502511
internal expect val isJs: Boolean
512+
internal expect val iterations_100_000 : Int

krpc/krpc-test/src/commonTest/kotlin/kotlinx/rpc/krpc/test/LocalTransportTest.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,7 @@ class ProtoBufLocalTransportTest : LocalTransportTest() {
6565

6666
@Test
6767
override fun testNullableLists(): TestResult = runTest { }
68+
69+
@Test
70+
override fun testNullableEnums(): TestResult = runTest { }
6871
}

krpc/krpc-test/src/commonTest/kotlin/kotlinx/rpc/krpc/test/TransportTest.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,12 +258,12 @@ class TransportTest {
258258

259259
val server = serverOf(transports)
260260

261-
delay(1000)
261+
withContext(Dispatchers.Default) { delay(1000) }
262262
val echoServices = server.registerServiceAndReturn<Echo, _> { EchoImpl() }
263263
assertEquals("foo", firstResult.await())
264264
assertEquals(1, echoServices.single().received.value)
265265

266-
delay(1000)
266+
withContext(Dispatchers.Default) { delay(1000) }
267267
val secondServices = server.registerServiceAndReturn<Second, _> { SecondServer() }
268268
assertEquals("bar", secondResult.await())
269269
assertEquals(1, secondServices.single().received.value)
@@ -272,6 +272,7 @@ class TransportTest {
272272
}
273273

274274
private val handshakeClassSerialName = KrpcProtocolMessage.Handshake.serializer().descriptor.serialName
275+
275276
@Suppress("RegExpRedundantEscape") // fails on js otherwise
276277
private val clientHandshake = ".*\\[Client\\] \\[Send\\] \\{\"type\":\"$handshakeClassSerialName\".*".toRegex()
277278

@@ -299,7 +300,7 @@ class TransportTest {
299300
server.registerServiceAndReturn<Second, _> { SecondServer() }
300301

301302
client.withService<Echo>().apply { echo("foo"); echo("bar") }
302-
client.withService<Second>().apply{ second("bar"); second("baz") }
303+
client.withService<Second>().apply { second("bar"); second("baz") }
303304

304305
assertEquals(1, transportInitialized.value)
305306
assertEquals(1, configInitialized.value)

krpc/krpc-test/src/jsMain/kotlin/kotlinx/rpc/krpc/test/KrpcTransportTestBase.js.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
package kotlinx.rpc.krpc.test
66

77
actual val isJs: Boolean = true
8+
internal actual val iterations_100_000: Int = 10_000

krpc/krpc-test/src/jsTest/kotlin/kotlinx/rpc/krpc/test/TransportTest.js.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44

55
package kotlinx.rpc.krpc.test
66

7-
internal actual val testIterations: Int = 100
7+
internal actual val testIterations: Int = 10

krpc/krpc-test/src/jvmMain/kotlin/kotlinx/rpc/krpc/test/KrpcTransportTestBase.jvm.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
package kotlinx.rpc.krpc.test
66

77
actual val isJs: Boolean = false
8+
internal actual val iterations_100_000: Int = 100_000

0 commit comments

Comments
 (0)