From d03b186a87bd8dd48e5af148b52ecb914c288909 Mon Sep 17 00:00:00 2001 From: jee-hyun-kim Date: Fri, 29 Mar 2024 19:17:21 +0900 Subject: [PATCH] fix presence events handling --- gradle.properties | 2 +- .../kotlin/dev/yorkie/core/DocumentTest.kt | 56 +++++++++---------- .../kotlin/dev/yorkie/document/Document.kt | 3 + 3 files changed, 30 insertions(+), 31 deletions(-) diff --git a/gradle.properties b/gradle.properties index 0f05e54ae..27e75697f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -11,7 +11,7 @@ android.suppressUnsupportedOptionWarnings=android.suppressUnsupportedOptionWarni kotlin.code.style=official kotlin.mpp.stability.nowarn=true GROUP=dev.yorkie -VERSION_NAME=0.4.15-rc3 +VERSION_NAME=0.4.15 POM_DESCRIPTION=Document store for building collaborative editing applications. POM_INCEPTION_YEAR=2022 POM_URL=https://github.com/yorkie-team/yorkie-android-sdk diff --git a/yorkie/src/androidTest/kotlin/dev/yorkie/core/DocumentTest.kt b/yorkie/src/androidTest/kotlin/dev/yorkie/core/DocumentTest.kt index 92f5ee728..adb7e2b4a 100644 --- a/yorkie/src/androidTest/kotlin/dev/yorkie/core/DocumentTest.kt +++ b/yorkie/src/androidTest/kotlin/dev/yorkie/core/DocumentTest.kt @@ -141,43 +141,39 @@ class DocumentTest { @Test fun test_removed_document_detachment() { - withTwoClientsAndDocuments(false) { client1, client2, document1, document2, _ -> - document1.updateAsync { root, _ -> + runBlocking { + val c1 = createClient() + val c2 = createClient() + val documentKey = UUID.randomUUID().toString().toDocKey() + val d1 = Document(documentKey) + val d2 = Document(documentKey) + + d1.updateAsync { root, _ -> root["key"] = 1 }.await() - assertEquals("""{"key":1}""", document1.toJson()) + c1.activateAsync().await() + c1.attachAsync(d1, isRealTimeSync = false).await() + assertEquals("""{"key":1}""", d1.toJson()) - client1.syncAsync().await() - client2.syncAsync().await() - assertEquals(document1.toJson(), document2.toJson()) + c2.activateAsync().await() + c2.attachAsync(d2, isRealTimeSync = false).await() + assertEquals("""{"key":1}""", d2.toJson()) - client1.removeAsync(document1).await() - if (document2.status != DocumentStatus.Removed) { - client2.detachAsync(document2).await() - } - assertEquals(DocumentStatus.Removed, document1.status) - assertEquals(DocumentStatus.Removed, document2.status) - } - } + c1.removeAsync(d1).await() + c2.removeAsync(d2).await() - @Test - fun test_removing_already_removed_document() { - withTwoClientsAndDocuments(false) { client1, client2, document1, document2, _ -> - document1.updateAsync { root, _ -> - root["key"] = 1 - }.await() - assertEquals("""{"key":1}""", document1.toJson()) + c1.syncAsync().await() + c2.syncAsync().await() - client1.syncAsync().await() - client2.syncAsync().await() - assertEquals(document1.toJson(), document2.toJson()) + assertEquals(DocumentStatus.Removed, d1.status) + assertEquals(DocumentStatus.Removed, d2.status) - client1.removeAsync(document1).await() - if (document2.status == DocumentStatus.Attached) { - client2.removeAsync(document2).await() - } - assertEquals(DocumentStatus.Removed, document1.status) - assertEquals(DocumentStatus.Removed, document2.status) + c1.deactivateAsync().await() + c2.deactivateAsync().await() + d1.close() + d2.close() + c1.close() + c2.close() } } diff --git a/yorkie/src/main/kotlin/dev/yorkie/document/Document.kt b/yorkie/src/main/kotlin/dev/yorkie/document/Document.kt index 446263042..bf133722e 100644 --- a/yorkie/src/main/kotlin/dev/yorkie/document/Document.kt +++ b/yorkie/src/main/kotlin/dev/yorkie/document/Document.kt @@ -335,6 +335,9 @@ public class Document( } private suspend fun emitPresences(newPresences: Presences) { + if (newPresences == _presences.value) { + publishPresenceEvent(newPresences) + } _presences.emit(newPresences) clone = ensureClone().copy(presences = newPresences) }