Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion karma/chrome_bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ config.set({
"client": {
captureConsole: true,
"mocha": {
timeout: 10000
timeout: 300000
}
}
});
Expand Down
8 changes: 0 additions & 8 deletions krpc/krpc-test/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,6 @@ tasks.named<Delete>("clean") {
delete(resourcesPath.walk().filter { it.isFile && it.extension == tmpExt }.toList())
}

tasks.withType<KotlinJsTest> {
onlyIf {
// for some reason browser tests don't wait for the test to complete and end immediately
// KRPC-166
!targetName.orEmpty().endsWith("browser")
}
}

tasks.register("moveToGold") {
doLast {
resourcesPath.walk().forEach {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,17 @@ interface KrpcTestService {

suspend fun nullableInt(v: Int?): Int?
suspend fun nullableList(v: List<Int>?): List<Int>?
suspend fun nullableEnum(enum: TestEnum?): TestEnum?
fun delayForever(): Flow<Boolean>

suspend fun answerToAnything(arg: String): Int

suspend fun krpc173()

fun unitFlow(): Flow<Unit>

@Serializable
enum class TestEnum {
ENUM_VALUE_1, ENUM_VALUE_2
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ class KrpcTestServiceBackend : KrpcTestService {

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

override fun delayForever(): Flow<Boolean> = flow {
emit(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ abstract class KrpcTransportTestBase {

@Test
fun RPC_should_be_able_to_receive_100_000_ints_in_reasonable_time() = runTest(timeout = EXTENDED_TIMEOUT) {
val n = 100_000
val n = iterations_100_000
var counter = 0
val last = client.getNInts(n).onEach {
counter++
Expand All @@ -336,8 +336,8 @@ abstract class KrpcTransportTestBase {
}

@Test
fun RPC_should_be_able_to_receive_100_000_ints_with_batching_in_reasonable_time() = runTest {
val n = 100_000
fun RPC_should_be_able_to_receive_100_000_ints_with_batching_in_reasonable_time() = runTest(timeout = EXTENDED_TIMEOUT) {
val n = iterations_100_000
assertEquals(client.getNIntsBatched(n).last().last(), n)
}

Expand Down Expand Up @@ -400,6 +400,15 @@ abstract class KrpcTransportTestBase {
assertEquals(listOf(1), client.nullableList(listOf(1)))
}

@Test
open fun testNullableEnums() = runTest {
assertNull(client.nullableEnum(null))
assertEquals(
KrpcTestService.TestEnum.ENUM_VALUE_1,
client.nullableEnum(KrpcTestService.TestEnum.ENUM_VALUE_1),
)
}

@Test
fun testServerCallCancellation() = runTest {
val flag: Channel<Boolean> = Channel()
Expand Down Expand Up @@ -500,3 +509,4 @@ abstract class KrpcTransportTestBase {
private val EXTENDED_TIMEOUT = if (isJs) 500.seconds else 200.seconds

internal expect val isJs: Boolean
internal expect val iterations_100_000 : Int
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,7 @@ class ProtoBufLocalTransportTest : LocalTransportTest() {

@Test
override fun testNullableLists(): TestResult = runTest { }

@Test
override fun testNullableEnums(): TestResult = runTest { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -258,12 +258,18 @@ class TransportTest {

val server = serverOf(transports)

delay(1000)
repeat(10) {
// give way to requests
yield()
}
val echoServices = server.registerServiceAndReturn<Echo, _> { EchoImpl() }
assertEquals("foo", firstResult.await())
assertEquals(1, echoServices.single().received.value)

delay(1000)
repeat(10) {
// give way to requests
yield()
}
val secondServices = server.registerServiceAndReturn<Second, _> { SecondServer() }
assertEquals("bar", secondResult.await())
assertEquals(1, secondServices.single().received.value)
Expand All @@ -272,6 +278,7 @@ class TransportTest {
}

private val handshakeClassSerialName = KrpcProtocolMessage.Handshake.serializer().descriptor.serialName

@Suppress("RegExpRedundantEscape") // fails on js otherwise
private val clientHandshake = ".*\\[Client\\] \\[Send\\] \\{\"type\":\"$handshakeClassSerialName\".*".toRegex()

Expand Down Expand Up @@ -299,7 +306,7 @@ class TransportTest {
server.registerServiceAndReturn<Second, _> { SecondServer() }

client.withService<Echo>().apply { echo("foo"); echo("bar") }
client.withService<Second>().apply{ second("bar"); second("baz") }
client.withService<Second>().apply { second("bar"); second("baz") }

assertEquals(1, transportInitialized.value)
assertEquals(1, configInitialized.value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,25 +127,33 @@ class CancellationTest {
service.cancellationInOutgoingStream(
stream = flow {
emit(42)
println("[testCancellationInClientStream] emit 42")
emit(43)
println("[testCancellationInClientStream] emit 43")
},
cancelled = flow {
emit(1)
println("[testCancellationInClientStream] emit 1")
serverInstance().firstIncomingConsumed.await()
println("[testCancellationInClientStream] firstIncomingConsumed")
throw CancellationException("cancellationInClientStream")
},
)
}

requestJob.join()
println("[testCancellationInClientStream] Request job finished")
serverInstance().consumedAll.await()
println("[testCancellationInClientStream] Server consumed all")

assertFalse(requestJob.isCancelled, "Expected requestJob not to be cancelled")
assertContentEquals(listOf(42, 43), serverInstance().consumedIncomingValues)
}
println("[testCancellationInClientStream] Scope finished")

checkAlive()
stopAllAndJoin()
println("[testCancellationInClientStream] All done")

assertEquals(1, serverInstance().cancellationsCounter.value, "Expected 1 request to be cancelled")
}
Expand All @@ -154,19 +162,23 @@ class CancellationTest {
@Test
fun testCancelClient() = runCancellationTest {
val firstRequestJob = launch {
println("[testCancelClient] firstRequestJob started")
service.longRequest()
}

val secondService = client.withService<CancellationService>()

val secondRequestJob = launch {
println("[testCancelClient] secondRequestJob started")
secondService.longRequest()
}

val clientFlowJob = launch {
service.outgoingStream(flow {
emit(0)
println("[testCancelClient] emit 0")
serverInstance().fence.await()
println("[testCancelClient] fence awaited")
emit(1)
})
}
Expand All @@ -181,18 +193,27 @@ class CancellationTest {
}
}

println("[testCancelClient] Requests sent")
serverInstance().waitCounter.await(4)
println("[testCancelClient] Requests reached")
client.close()
client.awaitCompletion()
println("[testCancelClient] Client stopped")
server.awaitCompletion()
println("[testCancelClient] Server stopped")
firstRequestJob.join()
println("[testCancelClient] First request finished")
secondRequestJob.join()
println("[testCancelClient] Second request finished")
clientFlowJob.join()
println("[testCancelClient] Client flow finished")

serverInstance().fence.complete(Unit)
serverFlowJob.join()
println("[testCancelClient] Server flow finished")

serverInstance().cancellationsCounter.await(4)
println("[testCancelClient] Server cancellations counted")

assertTrue(firstRequestJob.isCancelled, "Expected firstRequestJob to be cancelled")
assertTrue(secondRequestJob.isCancelled, "Expected secondRequestJob to be cancelled")
Expand All @@ -203,26 +224,31 @@ class CancellationTest {

checkAlive(clientAlive = false, serverAlive = false)
stopAllAndJoin()
println("[testCancelClient] All done")

assertEquals(4, serverInstance().cancellationsCounter.value, "Expected 4 requests to be cancelled")
}

@Test
fun testCancelServer() = runCancellationTest {
val firstRequestJob = launch {
println("[testCancelServer] firstRequestJob started")
service.longRequest()
}

val secondService = client.withService<CancellationService>()

val secondRequestJob = launch {
println("[testCancelServer] secondRequestJob started")
secondService.longRequest()
}

val clientFlowJob = launch {
service.outgoingStream(flow {
emit(0)
println("[testCancelServer] emit 0")
serverInstance().fence.await()
println("[testCancelServer] fence awaited")
emit(1)
})
}
Expand All @@ -237,18 +263,27 @@ class CancellationTest {
}
}

println("[testCancelServer] Requests sent")
serverInstance().waitCounter.await(4) // wait for requests to reach server
println("[testCancelServer] Requests reached")
server.close()
server.awaitCompletion()
println("[testCancelServer] Server stopped")
client.awaitCompletion()
println("[testCancelServer] Client stopped")
firstRequestJob.join()
println("[testCancelServer] First request finished")
secondRequestJob.join()
println("[testCancelServer] Second request finished")
clientFlowJob.join()
println("[testCancelServer] Client flow finished")

serverInstance().fence.complete(Unit)
serverFlowJob.join()
println("[testCancelServer] Server flow finished")

serverInstance().cancellationsCounter.await(4)
println("[testCancelServer] Server cancellations counted")

assertTrue(firstRequestJob.isCancelled, "Expected firstRequestJob to be cancelled")
assertTrue(secondRequestJob.isCancelled, "Expected secondRequestJob to be cancelled")
Expand All @@ -259,6 +294,7 @@ class CancellationTest {

checkAlive(clientAlive = false, serverAlive = false)
stopAllAndJoin()
println("[testCancelServer] All done")

assertEquals(4, serverInstance().cancellationsCounter.value, "Expected 4 requests to be cancelled")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
package kotlinx.rpc.krpc.test

actual val isJs: Boolean = true
internal actual val iterations_100_000: Int = 10_000
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

package kotlinx.rpc.krpc.test

internal actual val testIterations: Int = 100
internal actual val testIterations: Int = 10
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
package kotlinx.rpc.krpc.test

actual val isJs: Boolean = false
internal actual val iterations_100_000: Int = 100_000
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
package kotlinx.rpc.krpc.test

actual val isJs: Boolean = false
internal actual val iterations_100_000: Int = 100_000
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
package kotlinx.rpc.krpc.test

actual val isJs: Boolean = true
internal actual val iterations_100_000: Int = 10_000
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

package kotlinx.rpc.krpc.test

internal actual val testIterations: Int = 100
internal actual val testIterations: Int = 10
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
package kotlinx.rpc.krpc.test

internal actual val isJs: Boolean = true
internal actual val iterations_100_000: Int = 100_000