Skip to content

Commit

Permalink
add a test for sync all groups (#290)
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer authored Aug 21, 2024
1 parent c302b05 commit 3bff0b1
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
45 changes: 45 additions & 0 deletions library/src/androidTest/java/org/xmtp/android/library/GroupTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -892,4 +892,49 @@ class GroupTest {

assertEquals(preparedMessageId, message.id)
}

@Test
fun testSyncsAllGroupsInParallel() {
val boGroup = runBlocking {
boClient.conversations.newGroup(
listOf(
alix.walletAddress,
)
)
}
val boGroup2 = runBlocking {
boClient.conversations.newGroup(
listOf(
alix.walletAddress,
)
)
}
runBlocking { alixClient.conversations.syncGroups() }
val alixGroup: Group = alixClient.findGroup(boGroup.id)!!
val alixGroup2: Group = alixClient.findGroup(boGroup2.id)!!

assertEquals(alixGroup.messages().size, 0)
assertEquals(alixGroup2.messages().size, 0)

runBlocking {
boGroup.send("hi")
boGroup2.send("hi")
alixClient.conversations.syncAllGroups()
}

assertEquals(alixGroup.messages().size, 1)
assertEquals(alixGroup2.messages().size, 1)

runBlocking {
boGroup2.removeMembers(listOf(alix.walletAddress))
boGroup.send("hi")
boGroup.send("hi")
boGroup2.send("hi")
boGroup2.send("hi")
alixClient.conversations.syncAllGroups()
}

assertEquals(alixGroup.messages().size, 3)
assertEquals(alixGroup2.messages().size, 2)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,16 @@ data class Conversations(
return Group(client, group)
}

// Sync from the network the latest list of groups
suspend fun syncGroups() {
libXMTPConversations?.sync()
}

// Sync all existing local groups data from the network (Note: call syncGroups() first to get the latest list of groups)
suspend fun syncAllGroups() {
libXMTPConversations?.syncAllGroups()
}

suspend fun listGroups(
after: Date? = null,
before: Date? = null,
Expand Down

0 comments on commit 3bff0b1

Please sign in to comment.