From 578f69306272cc60c882376baf2684360af2aafd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus=20R=C3=B8rbech?= Date: Thu, 8 Aug 2024 14:27:08 +0200 Subject: [PATCH] Separate platform networking tests cases into separate methods --- .../mongodb/jvm/PlatformNetworkingTests.kt | 78 ++++++++++--------- 1 file changed, 43 insertions(+), 35 deletions(-) diff --git a/packages/test-sync/src/jvmTest/kotlin/io/realm/kotlin/test/mongodb/jvm/PlatformNetworkingTests.kt b/packages/test-sync/src/jvmTest/kotlin/io/realm/kotlin/test/mongodb/jvm/PlatformNetworkingTests.kt index 6dc295a0ad..b61ddeaa1d 100644 --- a/packages/test-sync/src/jvmTest/kotlin/io/realm/kotlin/test/mongodb/jvm/PlatformNetworkingTests.kt +++ b/packages/test-sync/src/jvmTest/kotlin/io/realm/kotlin/test/mongodb/jvm/PlatformNetworkingTests.kt @@ -29,47 +29,55 @@ class PlatformNetworkingTests { private val TIMEOUT = 10.seconds @Test - fun syncRoundTrip() = runBlocking { - setOf(false, true).forEach { platformNetworking -> - TestApp(this::class.simpleName, DefaultFlexibleSyncAppInitializer, builder = { - it.usePlatformNetworking(platformNetworking) - }).use { app -> - val selector = org.mongodb.kbson.ObjectId().toString() + fun syncRoundTrip_coreNetworking() = runBlocking { + roundTrip(platformNetworking = false) + } + + @Test + fun syncRoundTrip_platformNetworking() = runBlocking { + roundTrip(platformNetworking = true) + } - // Setup logger to capture WebSocketClient log messages - val logger = CustomLogCollector() - RealmLog.add(logger) - RealmLog.setLevel(LogLevel.ALL, LogCategory.Realm.Sdk) + private suspend fun roundTrip(platformNetworking: Boolean) { + TestApp(this::class.simpleName, DefaultFlexibleSyncAppInitializer, builder = { + it.usePlatformNetworking(platformNetworking) + }).use { app -> + val selector = org.mongodb.kbson.ObjectId().toString() - Realm.open(createSyncConfig(app.createUserAndLogIn(), selector)).use { uploadRealm -> - Realm.open(createSyncConfig(app.createUserAndLogIn(), selector)).use { realm -> - uploadRealm.write { - copyToRealm( - SyncObjectWithAllTypes().apply { - stringField = selector + // Setup logger to capture WebSocketClient log messages + val logger = CustomLogCollector() + RealmLog.add(logger) + RealmLog.setLevel(LogLevel.DEBUG, LogCategory.Realm.Sdk) + + Realm.open(createSyncConfig(app.createUserAndLogIn(), selector)) + .use { uploadRealm -> + Realm.open(createSyncConfig(app.createUserAndLogIn(), selector)) + .use { realm -> + uploadRealm.write { + copyToRealm( + SyncObjectWithAllTypes().apply { + stringField = selector + } + ) + } + uploadRealm.syncSession.uploadAllLocalChanges(TIMEOUT) + withTimeout(TIMEOUT) { + realm.query().asFlow().first { + it.list.size == 1 + }.list.first().also { + assertEquals(selector, it.stringField) } - ) - } - uploadRealm.syncSession.uploadAllLocalChanges(TIMEOUT) - withTimeout(TIMEOUT) { - realm.query().asFlow().first { - it.list.size == 1 - }.list.first().also { - assertEquals(selector, it.stringField) } } - } } - assertTrue( - if (platformNetworking) { - logger.logs.any { it.contains("\\[Websocket.*\\] onOpen".toRegex()) } - } else { - logger.logs.none { it.contains("\\[Websocket.*\\] onOpen".toRegex()) } - }, - "Failed to verify log statements for : platformNetworking=$platformNetworking" - ) - RealmLog.remove(logger) - } + assertTrue( + if (platformNetworking) { + logger.logs.any { it.contains("\\[Websocket.*\\] onOpen".toRegex()) } + } else { + logger.logs.none { it.contains("\\[Websocket.*\\] onOpen".toRegex()) } + }, + "Failed to verify log statements for : platformNetworking=$platformNetworking" + ) } }