Skip to content

Commit 49e94db

Browse files
authored
More Streaming and Threading Improvements (#192)
* bump the binaries * add v2 rust client to the client creation methods * make all send functions suspend * fix up the tests to not lock on send * Revert "make all send functions suspend" This reverts commit e4152d8. * Revert "Revert "make all send functions suspend"" This reverts commit 125d1ac. * fix lots of the threading issues * fix up the linter errors * bump to the latest rust library * make delay longer * clean up url usuage * bump to latest rust * incrementally making suspend functions better * remove the fake api client * use subscribe2 * remove rust v2 and the subscribe * remove subscribe entirely * make more suspend * bring back conversation tests * fix up the linter and some more tests * fix up the tests * get all the tests passing * everything takes a subscribe2 now * clean up the subscribe2 under the hood
1 parent 4ccb9b7 commit 49e94db

27 files changed

+456
-408
lines changed

library/src/androidTest/java/org/xmtp/android/library/AttachmentTest.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ class AttachmentTest {
2525

2626
val fixtures = fixtures()
2727
val aliceClient = fixtures.aliceClient
28-
val aliceConversation =
28+
val aliceConversation = runBlocking {
2929
aliceClient.conversations.newConversation(fixtures.bob.walletAddress)
30+
}
3031

3132
runBlocking {
3233
aliceConversation.send(

library/src/androidTest/java/org/xmtp/android/library/ClientTest.kt

+18-15
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ class ClientTest {
2626
fun testHasPrivateKeyBundleV1() {
2727
val fakeWallet = PrivateKeyBuilder()
2828
val client = Client().create(account = fakeWallet)
29-
assertEquals(1, client.privateKeyBundleV1?.preKeysList?.size)
30-
val preKey = client.privateKeyBundleV1?.preKeysList?.get(0)
29+
assertEquals(1, client.privateKeyBundleV1.preKeysList?.size)
30+
val preKey = client.privateKeyBundleV1.preKeysList?.get(0)
3131
assert(preKey?.publicKey?.hasSignature() ?: false)
3232
}
3333

@@ -50,15 +50,15 @@ class ClientTest {
5050
val fakeWallet = PrivateKeyBuilder()
5151
val client = Client().create(account = fakeWallet)
5252
val bundle = client.privateKeyBundle
53-
val clientFromV1Bundle = Client().buildFromBundle(bundle!!)
53+
val clientFromV1Bundle = Client().buildFromBundle(bundle)
5454
assertEquals(client.address, clientFromV1Bundle.address)
5555
assertEquals(
56-
client.privateKeyBundleV1?.identityKey,
57-
clientFromV1Bundle.privateKeyBundleV1?.identityKey,
56+
client.privateKeyBundleV1.identityKey,
57+
clientFromV1Bundle.privateKeyBundleV1.identityKey,
5858
)
5959
assertEquals(
60-
client.privateKeyBundleV1?.preKeysList,
61-
clientFromV1Bundle.privateKeyBundleV1?.preKeysList,
60+
client.privateKeyBundleV1.preKeysList,
61+
clientFromV1Bundle.privateKeyBundleV1.preKeysList,
6262
)
6363
}
6464

@@ -67,15 +67,15 @@ class ClientTest {
6767
val fakeWallet = PrivateKeyBuilder()
6868
val client = Client().create(account = fakeWallet)
6969
val bundleV1 = client.v1keys
70-
val clientFromV1Bundle = Client().buildFromV1Bundle(bundleV1!!)
70+
val clientFromV1Bundle = Client().buildFromV1Bundle(bundleV1)
7171
assertEquals(client.address, clientFromV1Bundle.address)
7272
assertEquals(
73-
client.privateKeyBundleV1?.identityKey,
74-
clientFromV1Bundle.privateKeyBundleV1?.identityKey,
73+
client.privateKeyBundleV1.identityKey,
74+
clientFromV1Bundle.privateKeyBundleV1.identityKey,
7575
)
7676
assertEquals(
77-
client.privateKeyBundleV1?.preKeysList,
78-
clientFromV1Bundle.privateKeyBundleV1?.preKeysList,
77+
client.privateKeyBundleV1.preKeysList,
78+
clientFromV1Bundle.privateKeyBundleV1.preKeysList,
7979
)
8080
}
8181

@@ -93,7 +93,8 @@ class ClientTest {
9393
assert(client.canMessageV3(listOf(client.address)))
9494

9595
val bundle = client.privateKeyBundle
96-
val clientFromV1Bundle = Client().buildFromBundle(bundle, account = fakeWallet, options = options)
96+
val clientFromV1Bundle =
97+
Client().buildFromBundle(bundle, account = fakeWallet, options = options)
9798
assertEquals(client.address, clientFromV1Bundle.address)
9899
assertEquals(
99100
client.privateKeyBundleV1.identityKey,
@@ -147,8 +148,10 @@ class ClientTest {
147148
appContext = context
148149
)
149150
)
150-
client.conversations.newGroup(listOf(client2.address,))
151-
runBlocking { client.conversations.syncGroups() }
151+
runBlocking {
152+
client.conversations.newGroup(listOf(client2.address))
153+
client.conversations.syncGroups()
154+
}
152155
assertEquals(client.conversations.listGroups().size, 1)
153156

154157
client.deleteLocalDatabase()

library/src/androidTest/java/org/xmtp/android/library/CodecTest.kt

+16-10
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@ class CodecTest {
5959
Client.register(codec = NumberCodec())
6060
val fixtures = fixtures()
6161
val aliceClient = fixtures.aliceClient
62-
val aliceConversation =
62+
val aliceConversation = runBlocking {
6363
aliceClient.conversations.newConversation(fixtures.bob.walletAddress)
64+
}
6465
runBlocking {
6566
aliceConversation.send(
6667
content = 3.14,
@@ -81,8 +82,9 @@ class CodecTest {
8182
Client.register(codec = CompositeCodec())
8283
val fixtures = fixtures()
8384
val aliceClient = fixtures.aliceClient
84-
val aliceConversation =
85+
val aliceConversation = runBlocking {
8586
aliceClient.conversations.newConversation(fixtures.bob.walletAddress)
87+
}
8688
val textContent = TextCodec().encode(content = "hiya")
8789
val source = DecodedComposite(encodedContent = textContent)
8890
runBlocking {
@@ -102,8 +104,9 @@ class CodecTest {
102104
Client.register(codec = NumberCodec())
103105
val fixtures = fixtures()
104106
val aliceClient = fixtures.aliceClient!!
105-
val aliceConversation =
107+
val aliceConversation = runBlocking {
106108
aliceClient.conversations.newConversation(fixtures.bob.walletAddress)
109+
}
107110
val textContent = TextCodec().encode(content = "sup")
108111
val numberContent = NumberCodec().encode(content = 3.14)
109112
val source = DecodedComposite(
@@ -131,9 +134,10 @@ class CodecTest {
131134
val codec = NumberCodec()
132135
Client.register(codec = codec)
133136
val fixtures = fixtures()
134-
val aliceClient = fixtures.aliceClient!!
135-
val aliceConversation =
137+
val aliceClient = fixtures.aliceClient
138+
val aliceConversation = runBlocking {
136139
aliceClient.conversations.newConversation(fixtures.bob.walletAddress)
140+
}
137141
runBlocking {
138142
aliceConversation.send(
139143
content = 3.14,
@@ -165,12 +169,14 @@ class CodecTest {
165169
repeat(5) {
166170
val account = PrivateKeyBuilder()
167171
val client = Client().create(account, clientOptions)
168-
conversations.add(
169-
alixClient.conversations.newConversation(
170-
client.address,
171-
context = InvitationV1ContextBuilder.buildFromConversation(conversationId = "hi")
172+
runBlocking {
173+
conversations.add(
174+
alixClient.conversations.newConversation(
175+
client.address,
176+
context = InvitationV1ContextBuilder.buildFromConversation(conversationId = "hi")
177+
)
172178
)
173-
)
179+
}
174180
}
175181

176182
val thirtyDayPeriodsSinceEpoch = Instant.now().epochSecond / 60 / 60 / 24 / 30

library/src/androidTest/java/org/xmtp/android/library/ContactsTest.kt

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import org.junit.Assert.assertEquals
55
import org.junit.Test
66
import org.junit.runner.RunWith
77
import org.xmtp.android.library.messages.walletAddress
8+
89
@RunWith(AndroidJUnit4::class)
910
class ContactsTest {
1011

0 commit comments

Comments
 (0)