From ee9ea196be91d6a97960fe5873bd4eed3ca9a2b7 Mon Sep 17 00:00:00 2001 From: cbullinger Date: Tue, 23 Jan 2024 14:47:29 -0500 Subject: [PATCH] Fix hanging tests --- .../com/mongodb/realm/realmkmmapp/ReadTest.kt | 15 ++++++--------- ...ReadTest.snippet.query-inverse-relationship.kt | 3 ++- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/examples/kotlin/shared/src/commonTest/kotlin/com/mongodb/realm/realmkmmapp/ReadTest.kt b/examples/kotlin/shared/src/commonTest/kotlin/com/mongodb/realm/realmkmmapp/ReadTest.kt index 19cde708fd..406db6eab2 100644 --- a/examples/kotlin/shared/src/commonTest/kotlin/com/mongodb/realm/realmkmmapp/ReadTest.kt +++ b/examples/kotlin/shared/src/commonTest/kotlin/com/mongodb/realm/realmkmmapp/ReadTest.kt @@ -18,7 +18,6 @@ import io.realm.kotlin.types.annotations.PrimaryKey import kotlinx.coroutines.Deferred import kotlinx.coroutines.async import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.count import org.mongodb.kbson.ObjectId import kotlin.test.Test import kotlin.test.assertEquals @@ -158,7 +157,7 @@ class ReadTest: RealmTest() { owner = "Jim Henson" }) } - realm.write{ + realm.writeBlocking{ // :snippet-start: synchronous-query val queryAllFrogs = realm.query() val queryAllLiveFrogs = this.query() // this: MutableRealm @@ -175,11 +174,7 @@ class ReadTest: RealmTest() { val allLiveFrogsFlow: Flow> = queryAllLiveFrogs.asFlow() // throws exception // :snippet-end: } - assertTrue(thrownException.message!!.contains("Observing changes are not supported by this Realm")) - val testFlow: Deferred = async { - assertEquals(3, allFrogsFlow.count()) - } - testFlow.cancel() + assertTrue(thrownException.message!!.contains("Observing changes are not supported by this Realm")) assertEquals(3, allFrogs.size) assertEquals(3, allLiveFrogs.size) deleteAll() @@ -656,7 +651,8 @@ class ReadTest: RealmTest() { copyToRealm(user) } realm.write { - val dateMinusFiveYears = RealmInstant.from(1677628500, 0) // Feb 28 2023 + val today = RealmInstant.now() + //RealmInstant.from(1677628500, 0) // Feb 28 2023 // :snippet-start: query-inverse-relationship // Query the parent object to access the child objects val user = query("name == $0", "Kermit").find().first() @@ -669,7 +665,8 @@ class ReadTest: RealmTest() { } // Query the backlink with `@links..` - val oldPostsByKermit = query("@links.ExampleRelationship_User.posts.date < $0", dateMinusFiveYears) + val oldPostsByKermit = realm.query() + .query("@links.ExampleRelationship_User.posts.name == $0 AND date < $1", "Kermit", today) .find() assertEquals(2, oldPostsByKermit.size) // :remove: diff --git a/source/examples/generated/kotlin/ReadTest.snippet.query-inverse-relationship.kt b/source/examples/generated/kotlin/ReadTest.snippet.query-inverse-relationship.kt index 30e2b5645b..32954f2b39 100644 --- a/source/examples/generated/kotlin/ReadTest.snippet.query-inverse-relationship.kt +++ b/source/examples/generated/kotlin/ReadTest.snippet.query-inverse-relationship.kt @@ -8,7 +8,8 @@ user.posts.forEach { post -> } // Query the backlink with `@links..` -val oldPostsByKermit = query("@links.User.posts.date < $0", dateMinusFiveYears) +val oldPostsByKermit = realm.query() + .query("@links.User.posts.name == $0 AND date < $1", "Kermit", today) .find() // Query the child object to access the parent