Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Melchior committed Oct 4, 2023
1 parent 2c1feae commit 17866c6
Show file tree
Hide file tree
Showing 18 changed files with 89 additions and 97 deletions.
2 changes: 1 addition & 1 deletion dependencies.list
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Version of MongoDB Realm used by integration tests
# See https://github.com/realm/ci/packages/147854 for available versions
MONGODB_REALM_SERVER=2023-10-03
MONGODB_REALM_SERVER=2023-10-04

# `BAAS` and `BAAS-UI` projects commit hashes matching MONGODB_REALM_SERVER image version
# note that the MONGODB_REALM_SERVER image is a nightly build, find the matching commits
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class AsymmetricSyncTests {
}
config = SyncConfiguration.Builder(
user,
schema = SYNC_SCHEMA
schema = FLEXIBLE_SYNC_SCHEMA
).initialSubscriptions {
it.query<DeviceParent>().subscribe()
}.build()
Expand Down Expand Up @@ -294,7 +294,7 @@ class AsymmetricSyncTests {
fun asymmetricSchema() = runBlocking {
config = SyncConfiguration.Builder(
app.login(Credentials.anonymous()),
schema = SYNC_SCHEMA
schema = FLEXIBLE_SYNC_SCHEMA
).build()
Realm.open(config).use {
it.write {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import io.realm.kotlin.entities.sync.flx.FlexEmbeddedObject
import io.realm.kotlin.entities.sync.flx.FlexParentObject
import io.realm.kotlin.ext.query
import io.realm.kotlin.internal.platform.runBlocking
import io.realm.kotlin.log.LogLevel
import io.realm.kotlin.mongodb.exceptions.CompensatingWriteException
import io.realm.kotlin.mongodb.exceptions.DownloadingRealmTimeOutException
import io.realm.kotlin.mongodb.exceptions.SyncException
Expand Down Expand Up @@ -63,7 +62,7 @@ class FlexibleSyncIntegrationTests {

@BeforeTest
fun setup() {
app = TestApp(this::class.simpleName, appName = TEST_APP_FLEX, logLevel = LogLevel.ALL)
app = TestApp(this::class.simpleName, appName = TEST_APP_FLEX)
val (email, password) = TestHelper.randomEmail() to "password1234"
runBlocking {
app.createUserAndLogIn(email, password)
Expand All @@ -83,7 +82,7 @@ class FlexibleSyncIntegrationTests {

// Upload data from user 1
val user1 = app.createUserAndLogIn(TestHelper.randomEmail(), "123456")
val config1 = SyncConfiguration.create(user1, SYNC_SCHEMA)
val config1 = SyncConfiguration.create(user1, FLEXIBLE_SYNC_SCHEMA)
Realm.open(config1).use { realm1 ->
val subs = realm1.subscriptions.update {
add(realm1.query<FlexParentObject>("section = $0", randomSection))
Expand All @@ -98,7 +97,7 @@ class FlexibleSyncIntegrationTests {

// Download data from user 2
val user2 = app.createUserAndLogIn(TestHelper.randomEmail(), "123456")
val config2 = SyncConfiguration.Builder(user2, SYNC_SCHEMA)
val config2 = SyncConfiguration.Builder(user2, FLEXIBLE_SYNC_SCHEMA)
.initialSubscriptions { realm ->
add(
realm.query<FlexParentObject>(
Expand All @@ -119,7 +118,7 @@ class FlexibleSyncIntegrationTests {
@Test
fun writeFailsIfNoSubscription() = runBlocking {
val user = app.createUserAndLogIn(TestHelper.randomEmail(), "123456")
val config = SyncConfiguration.Builder(user, SYNC_SCHEMA)
val config = SyncConfiguration.Builder(user, FLEXIBLE_SYNC_SCHEMA)
.build()

Realm.open(config).use { realm ->
Expand All @@ -137,7 +136,7 @@ class FlexibleSyncIntegrationTests {
val randomSection = Random.nextInt() // Generate random section to allow replays of unit tests

val user = app.createUserAndLogIn(TestHelper.randomEmail(), "123456")
val config = SyncConfiguration.Builder(user, SYNC_SCHEMA).build()
val config = SyncConfiguration.Builder(user, FLEXIBLE_SYNC_SCHEMA).build()
Realm.open(config).use { realm ->
realm.subscriptions.update {
val query = realm.query<FlexParentObject>()
Expand All @@ -162,7 +161,7 @@ class FlexibleSyncIntegrationTests {

@Test
fun initialSubscriptions_timeOut() {
val config = SyncConfiguration.Builder(app.currentUser!!, SYNC_SCHEMA)
val config = SyncConfiguration.Builder(app.currentUser!!, FLEXIBLE_SYNC_SCHEMA)
.initialSubscriptions { realm ->
repeat(10) {
add(realm.query<FlexParentObject>("section = $0", it))
Expand All @@ -185,7 +184,7 @@ class FlexibleSyncIntegrationTests {

// Prepare some user data
val user1 = app.createUserAndLogin()
val config1 = SyncConfiguration.create(user1, SYNC_SCHEMA)
val config1 = SyncConfiguration.create(user1, FLEXIBLE_SYNC_SCHEMA)
Realm.open(config1).use { realm ->
realm.subscriptions.update {
add(realm.query<FlexParentObject>("section = $0", randomSection))
Expand All @@ -207,7 +206,7 @@ class FlexibleSyncIntegrationTests {
// User 2 opens a Realm twice
val counter = atomic(0)
val user2 = app.createUserAndLogin()
val config2 = SyncConfiguration.Builder(user2, SYNC_SCHEMA)
val config2 = SyncConfiguration.Builder(user2, FLEXIBLE_SYNC_SCHEMA)
.initialSubscriptions(rerunOnOpen = true) { realm ->
add(
realm.query<FlexParentObject>(
Expand Down Expand Up @@ -235,7 +234,7 @@ class FlexibleSyncIntegrationTests {

// Upload data from user 1
val user1 = app.createUserAndLogIn(TestHelper.randomEmail(), "123456")
val config1 = SyncConfiguration.create(user1, SYNC_SCHEMA)
val config1 = SyncConfiguration.create(user1, FLEXIBLE_SYNC_SCHEMA)
Realm.open(config1).use { realm1 ->
val subs = realm1.subscriptions.update {
add(realm1.query<FlexParentObject>("section = $0", randomSection))
Expand Down Expand Up @@ -273,7 +272,7 @@ class FlexibleSyncIntegrationTests {

// Download data from user 2
val user2 = app.createUserAndLogIn(TestHelper.randomEmail(), "123456")
val config2 = SyncConfiguration.Builder(user2, SYNC_SCHEMA)
val config2 = SyncConfiguration.Builder(user2, FLEXIBLE_SYNC_SCHEMA)
.initialSubscriptions { realm ->
add(
realm.query<FlexParentObject>(
Expand Down Expand Up @@ -304,7 +303,7 @@ class FlexibleSyncIntegrationTests {

val channel = Channel<CompensatingWriteException>(1)

val config1 = SyncConfiguration.Builder(user1, SYNC_SCHEMA)
val config1 = SyncConfiguration.Builder(user1, FLEXIBLE_SYNC_SCHEMA)
.errorHandler { _: SyncSession, syncException: SyncException ->
runBlocking {
channel.send(syncException as CompensatingWriteException)
Expand Down Expand Up @@ -332,7 +331,7 @@ class FlexibleSyncIntegrationTests {

val exception: CompensatingWriteException = channel.receiveOrFail()

assertTrue(exception.message!!.startsWith("[Sync][CompensatingWrite(1033)] Client attempted a write that is outside of permissions or query filters; it has been reverted Logs:"), exception.message)
assertTrue(exception.message!!.startsWith("[Sync][CompensatingWrite(1033)] Client attempted a write that is not allowed; it has been reverted Logs:"), exception.message)
assertEquals(1, exception.writes.size)

exception.writes[0].run {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1015,7 +1015,7 @@ class FunctionsTests {
runBlocking {
anonUser.logOut()
}
assertFailsWithMessage<ServiceException>("[Service][Unknown(4351)] expected Authorization header with JWT") {
assertFailsWithMessage<ServiceException>("[Service][Unknown(4351)] unauthorized") {
runBlocking {
functions.call(FIRST_ARG_FUNCTION.name, 1, 2, 3)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class GeoSpatialTests {
val config =
SyncConfiguration.Builder(
user = user,
schema = SYNC_SCHEMA
schema = FLEXIBLE_SYNC_SCHEMA
).initialSubscriptions {
add(it.query<SyncRestaurant>())
}.build()
Expand All @@ -94,7 +94,7 @@ class GeoSpatialTests {
val config =
SyncConfiguration.Builder(
user = user,
schema = SYNC_SCHEMA
schema = FLEXIBLE_SYNC_SCHEMA
).build()

Realm.open(config).use { realm ->
Expand Down Expand Up @@ -176,7 +176,7 @@ class GeoSpatialTests {
val config =
SyncConfiguration.Builder(
user = user1,
schema = SYNC_SCHEMA
schema = FLEXIBLE_SYNC_SCHEMA
).initialSubscriptions {
add(
it.query<SyncRestaurant>(
Expand Down Expand Up @@ -221,7 +221,7 @@ class GeoSpatialTests {
val config2 =
SyncConfiguration.Builder(
user = user2,
schema = SYNC_SCHEMA
schema = FLEXIBLE_SYNC_SCHEMA
).initialSubscriptions {
add(
it.query<SyncRestaurant>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package io.realm.kotlin.test.mongodb.common

import io.realm.kotlin.Realm
import io.realm.kotlin.entities.sync.flx.FlexChildObject
import io.realm.kotlin.entities.sync.flx.FlexEmbeddedObject
import io.realm.kotlin.entities.sync.flx.FlexParentObject
import io.realm.kotlin.ext.query
import io.realm.kotlin.internal.platform.runBlocking
Expand Down Expand Up @@ -64,7 +63,7 @@ class MutableSubscriptionSetTests {
}
config = SyncConfiguration.Builder(
user,
schema = SYNC_SCHEMA
schema = FLEXIBLE_SYNC_SCHEMA
)
.build()
realm = Realm.open(config)
Expand Down Expand Up @@ -284,7 +283,7 @@ class MutableSubscriptionSetTests {
// Not part of schema
realm.subscriptions.update {
assertFailsWith<IllegalArgumentException> {
removeAll(io.realm.kotlin.entities.sync.ParentPk::class)
removeAll(io.realm.kotlin.entities.Sample::class)
}
}

Expand Down Expand Up @@ -369,7 +368,7 @@ class MutableSubscriptionSetTests {

private suspend fun uploadServerData(sectionId: Int, noOfObjects: Int) {
val user = app.createUserAndLogin()
val config = SyncConfiguration.Builder(user, setOf(FlexParentObject::class, FlexChildObject::class, FlexEmbeddedObject::class))
val config = SyncConfiguration.Builder(user, FLEXIBLE_SYNC_SCHEMA)
.initialSubscriptions {
it.query<FlexParentObject>().subscribe()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ class ProgressListenerTests {
fun throwsOnFlexibleSync() = runBlocking {
TestApp("throwsOnFlexibleSync", TEST_APP_FLEX).use {
val user = app.createUserAndLogIn()
val configuration: SyncConfiguration = SyncConfiguration.create(user, SYNC_SCHEMA)
val configuration: SyncConfiguration = SyncConfiguration.create(user, FLEXIBLE_SYNC_SCHEMA)
Realm.open(configuration).use { realm ->
assertFailsWithMessage<UnsupportedOperationException>(
"Progress listeners are not supported for Flexible Sync"
Expand Down Expand Up @@ -304,7 +304,7 @@ class ProgressListenerTests {
user: User,
partitionValue: String = getTestPartitionValue()
): SyncConfiguration {
return SyncConfiguration.Builder(user, partitionValue, SYNC_SCHEMA)
return SyncConfiguration.Builder(user, partitionValue, PARTITION_BASED_SCHEMA)
.build()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
package io.realm.kotlin.test.mongodb.common

import io.realm.kotlin.entities.Location
import io.realm.kotlin.entities.sync.BinaryObject
import io.realm.kotlin.entities.sync.ChildPk
import io.realm.kotlin.entities.sync.ObjectIdPk
import io.realm.kotlin.entities.sync.ParentPk
import io.realm.kotlin.entities.sync.SyncObjectWithAllTypes
import io.realm.kotlin.entities.sync.SyncPerson
Expand All @@ -26,21 +28,28 @@ import io.realm.kotlin.entities.sync.flx.FlexChildObject
import io.realm.kotlin.entities.sync.flx.FlexEmbeddedObject
import io.realm.kotlin.entities.sync.flx.FlexParentObject

val SYNC_SCHEMA = setOf(
private val ASYMMETRIC_SCHEMAS = setOf(
AsymmetricSyncTests.AsymmetricA::class,
AsymmetricSyncTests.EmbeddedB::class,
AsymmetricSyncTests.StandardC::class,
Measurement::class,
)
private val DEFAULT_SCHEMAS = setOf(
BackupDevice::class,
BinaryObject::class,
ChildPk::class,
Device::class,
DeviceParent::class,
FlexChildObject::class,
FlexEmbeddedObject::class,
FlexParentObject::class,
Measurement::class,
ObjectIdPk::class,
ParentPk::class,
SyncObjectWithAllTypes::class,
SyncPerson::class,
SyncRestaurant::class,
Location::class,
)

val PARTITION_BASED_SCHEMA = DEFAULT_SCHEMAS
val FLEXIBLE_SYNC_SCHEMA = DEFAULT_SCHEMAS + ASYMMETRIC_SCHEMAS
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
package io.realm.kotlin.test.mongodb.common

import io.realm.kotlin.Realm
import io.realm.kotlin.entities.sync.flx.FlexChildObject
import io.realm.kotlin.entities.sync.flx.FlexEmbeddedObject
import io.realm.kotlin.entities.sync.flx.FlexParentObject
import io.realm.kotlin.ext.query
import io.realm.kotlin.internal.platform.runBlocking
Expand All @@ -45,7 +43,6 @@ import kotlin.test.assertFailsWith
import kotlin.test.assertNotEquals
import kotlin.test.assertNull
import kotlin.test.assertTrue
import kotlin.text.Typography.section
import kotlin.time.Duration.Companion.nanoseconds
import kotlin.time.Duration.Companion.seconds

Expand All @@ -67,7 +64,7 @@ class SubscriptionExtensionsTests {
}
val config = SyncConfiguration.Builder(
user,
schema = SYNC_SCHEMA
schema = FLEXIBLE_SYNC_SCHEMA
)
.build()
realm = Realm.open(config)
Expand Down Expand Up @@ -136,7 +133,7 @@ class SubscriptionExtensionsTests {
val user1 = app.createUserAndLogIn(email, password)
val config = SyncConfiguration.Builder(
user1,
schema = SYNC_SCHEMA
schema = FLEXIBLE_SYNC_SCHEMA
).initialSubscriptions { realm: Realm ->
realm.query<FlexParentObject>("section = $0", section).subscribe()
}.build()
Expand Down Expand Up @@ -394,7 +391,7 @@ class SubscriptionExtensionsTests {

private suspend fun uploadServerData(sectionId: Int, noOfObjects: Int) {
val user = app.createUserAndLogin()
val config = SyncConfiguration.Builder(user, setOf(FlexParentObject::class, FlexChildObject::class, FlexEmbeddedObject::class))
val config = SyncConfiguration.Builder(user, FLEXIBLE_SYNC_SCHEMA)
.initialSubscriptions {
it.query<FlexParentObject>().subscribe()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
package io.realm.kotlin.test.mongodb.common

import io.realm.kotlin.Realm
import io.realm.kotlin.entities.sync.flx.FlexChildObject
import io.realm.kotlin.entities.sync.flx.FlexEmbeddedObject
import io.realm.kotlin.entities.sync.flx.FlexParentObject
import io.realm.kotlin.ext.query
import io.realm.kotlin.internal.platform.runBlocking
Expand Down Expand Up @@ -64,7 +62,7 @@ class SubscriptionSetTests {
}
val config = SyncConfiguration.Builder(
user,
schema = SYNC_SCHEMA
schema = FLEXIBLE_SYNC_SCHEMA
)
.build()
realm = Realm.open(config)
Expand Down Expand Up @@ -98,7 +96,7 @@ class SubscriptionSetTests {
val config = SyncConfiguration.create(
user,
TestHelper.randomPartitionValue(),
setOf(FlexParentObject::class, FlexChildObject::class, FlexEmbeddedObject::class)
PARTITION_BASED_SCHEMA
)
Realm.open(config).use { partionBasedRealm ->
assertFailsWith<IllegalStateException> { partionBasedRealm.subscriptions }
Expand Down Expand Up @@ -192,7 +190,7 @@ class SubscriptionSetTests {
assertFailsWith<BadFlexibleSyncQueryException> {
subscriptions.waitForSynchronization()
}
assertTrue(subscriptions.errorMessage!!.contains("Client provided query with bad syntax"))
assertTrue(subscriptions.errorMessage!!.contains("Invalid query: invalid RQL for table \"FlexParentObject\": syntax error: unexpected Limit, expecting Or or RightParenthesis"))
subscriptions.update {
removeAll()
}
Expand Down Expand Up @@ -258,7 +256,7 @@ class SubscriptionSetTests {
updatedSubs.waitForSynchronization()
}
assertEquals(SubscriptionSetState.ERROR, updatedSubs.state)
assertTrue(updatedSubs.errorMessage!!.contains("Client provided query with bad syntax"))
assertTrue(updatedSubs.errorMessage!!.contains("Invalid query: invalid RQL for table \"FlexParentObject\": syntax error: unexpected Limit, expecting Or or RightParenthesis"))
}

// Test case for https://github.com/realm/realm-core/issues/5504
Expand All @@ -272,7 +270,7 @@ class SubscriptionSetTests {
}
assertEquals(SubscriptionSetState.ERROR, updatedSubs.state)
assertEquals("TRUEPREDICATE and TRUEPREDICATE LIMIT(1)", updatedSubs.first().queryDescription)
assertTrue(updatedSubs.errorMessage!!.contains("Client provided query with bad syntax"))
assertTrue(updatedSubs.errorMessage!!.contains("Invalid query: invalid RQL for table \"FlexParentObject\": syntax error: unexpected Limit, expecting Or or RightParenthesis"))
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class SubscriptionTests {
}
val config = SyncConfiguration.Builder(
user,
schema = SYNC_SCHEMA
schema = FLEXIBLE_SYNC_SCHEMA
)
.build()
realm = Realm.open(config)
Expand Down
Loading

0 comments on commit 17866c6

Please sign in to comment.