Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure every presence event is published #164

Merged
merged 1 commit into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading