Skip to content

Commit

Permalink
fix presence events handling (#164)
Browse files Browse the repository at this point in the history
  • Loading branch information
7hong13 authored Mar 29, 2024
1 parent 68a06c5 commit 8c2e63f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 31 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
56 changes: 26 additions & 30 deletions yorkie/src/androidTest/kotlin/dev/yorkie/core/DocumentTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

Expand Down
3 changes: 3 additions & 0 deletions yorkie/src/main/kotlin/dev/yorkie/document/Document.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 8c2e63f

Please sign in to comment.