Skip to content

Commit

Permalink
Update core and add platform networking tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rorbech committed Jul 17, 2024
1 parent fa54fe0 commit 8285baa
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1310,7 +1310,8 @@ actual object RealmInterop {
}

actual fun realm_app_config_get_sync_client_config(configPointer: RealmAppConfigurationPointer): RealmSyncClientConfigurationPointer {
return LongPointerWrapper(realmc.realm_app_config_get_sync_client_config(configPointer.cptr()))
// The configuration is owned by Core so don't track and release it through garbage collection of the NativePointer
return LongPointerWrapper(realmc.realm_app_config_get_sync_client_config(configPointer.cptr()), false)
}

actual fun realm_sync_client_config_set_default_binding_thread_observer(syncClientConfig: RealmSyncClientConfigurationPointer, appId: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2465,7 +2465,8 @@ actual object RealmInterop {
}

actual fun realm_app_config_get_sync_client_config(configPointer: RealmAppConfigurationPointer): RealmSyncClientConfigurationPointer {
return CPointerWrapper(realm_wrapper.realm_app_config_get_sync_client_config(configPointer.cptr()))
// The configuration is owned by Core so don't track and release it through garbage collection of the NativePointer
return CPointerWrapper(realm_wrapper.realm_app_config_get_sync_client_config(configPointer.cptr()), false)
}

actual fun realm_sync_client_config_set_default_binding_thread_observer(
Expand Down
2 changes: 1 addition & 1 deletion packages/external/core
Submodule core updated 267 files
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package io.realm.kotlin.test.mongodb.jvm

import io.realm.kotlin.Realm
import io.realm.kotlin.entities.sync.SyncObjectWithAllTypes
import io.realm.kotlin.ext.query
import io.realm.kotlin.internal.platform.runBlocking
import io.realm.kotlin.log.LogCategory
import io.realm.kotlin.log.LogLevel
import io.realm.kotlin.log.RealmLog
import io.realm.kotlin.mongodb.User
import io.realm.kotlin.mongodb.sync.SyncConfiguration
import io.realm.kotlin.mongodb.syncSession
import io.realm.kotlin.test.mongodb.TestApp
import io.realm.kotlin.test.mongodb.common.FLEXIBLE_SYNC_SCHEMA
import io.realm.kotlin.test.mongodb.common.utils.CustomLogCollector
import io.realm.kotlin.test.mongodb.createUserAndLogIn
import io.realm.kotlin.test.mongodb.use
import io.realm.kotlin.test.mongodb.util.DefaultFlexibleSyncAppInitializer
import io.realm.kotlin.test.util.use
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue
import kotlin.time.Duration.Companion.seconds

class PlatformNetworkingTests {

private val TIMEOUT = 10.seconds

@Test
fun syncRoundTrip() = runBlocking {
setOf(true, false).forEach { platformNetworking ->
TestApp(this::class.simpleName, DefaultFlexibleSyncAppInitializer, builder = {
it.usePlatformNetworking(platformNetworking)
}).use { app ->
val selector = org.mongodb.kbson.ObjectId().toString()

// 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)
realm.syncSession.downloadAllServerChanges(TIMEOUT)
assertEquals(1, realm.query<SyncObjectWithAllTypes>().find().size)
}
}
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"
)
}
}
}

private fun createSyncConfig(
user: User,
selector: String
): SyncConfiguration {
return SyncConfiguration.Builder(user, FLEXIBLE_SYNC_SCHEMA).initialSubscriptions {
add(it.query<SyncObjectWithAllTypes>("stringField = $0", selector))
}.build()
}
}

0 comments on commit 8285baa

Please sign in to comment.