Skip to content

Commit 10df0c4

Browse files
committed
Revert "Revert "make all send functions suspend""
This reverts commit 125d1ac.
1 parent 125d1ac commit 10df0c4

File tree

12 files changed

+519
-493
lines changed

12 files changed

+519
-493
lines changed

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

+7-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package org.xmtp.android.library
22

33
import androidx.test.ext.junit.runners.AndroidJUnit4
44
import com.google.protobuf.kotlin.toByteStringUtf8
5+
import kotlinx.coroutines.runBlocking
56
import org.junit.Assert.assertEquals
67
import org.junit.Test
78
import org.junit.runner.RunWith
@@ -27,10 +28,12 @@ class AttachmentTest {
2728
val aliceConversation =
2829
aliceClient.conversations.newConversation(fixtures.bob.walletAddress)
2930

30-
aliceConversation.send(
31-
content = attachment,
32-
options = SendOptions(contentType = ContentTypeAttachment),
33-
)
31+
runBlocking {
32+
aliceConversation.send(
33+
content = attachment,
34+
options = SendOptions(contentType = ContentTypeAttachment),
35+
)
36+
}
3437
val messages = aliceConversation.messages()
3538
assertEquals(messages.size, 1)
3639
if (messages.size == 1) {

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

+25-16
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package org.xmtp.android.library
22

33
import androidx.test.ext.junit.runners.AndroidJUnit4
44
import com.google.protobuf.kotlin.toByteStringUtf8
5+
import kotlinx.coroutines.runBlocking
56
import org.junit.Assert.assertEquals
67
import org.junit.Assert.assertTrue
78
import org.junit.Test
@@ -60,10 +61,12 @@ class CodecTest {
6061
val aliceClient = fixtures.aliceClient
6162
val aliceConversation =
6263
aliceClient.conversations.newConversation(fixtures.bob.walletAddress)
63-
aliceConversation.send(
64-
content = 3.14,
65-
options = SendOptions(contentType = NumberCodec().contentType),
66-
)
64+
runBlocking {
65+
aliceConversation.send(
66+
content = 3.14,
67+
options = SendOptions(contentType = NumberCodec().contentType),
68+
)
69+
}
6770
val messages = aliceConversation.messages()
6871
assertEquals(messages.size, 1)
6972
if (messages.size == 1) {
@@ -82,10 +85,12 @@ class CodecTest {
8285
aliceClient.conversations.newConversation(fixtures.bob.walletAddress)
8386
val textContent = TextCodec().encode(content = "hiya")
8487
val source = DecodedComposite(encodedContent = textContent)
85-
aliceConversation.send(
86-
content = source,
87-
options = SendOptions(contentType = CompositeCodec().contentType),
88-
)
88+
runBlocking {
89+
aliceConversation.send(
90+
content = source,
91+
options = SendOptions(contentType = CompositeCodec().contentType),
92+
)
93+
}
8994
val messages = aliceConversation.messages()
9095
val decoded: DecodedComposite? = messages[0].content()
9196
assertEquals("hiya", decoded?.content())
@@ -107,10 +112,12 @@ class CodecTest {
107112
DecodedComposite(parts = listOf(DecodedComposite(encodedContent = numberContent))),
108113
),
109114
)
110-
aliceConversation.send(
111-
content = source,
112-
options = SendOptions(contentType = CompositeCodec().contentType),
113-
)
115+
runBlocking {
116+
aliceConversation.send(
117+
content = source,
118+
options = SendOptions(contentType = CompositeCodec().contentType),
119+
)
120+
}
114121
val messages = aliceConversation.messages()
115122
val decoded: DecodedComposite? = messages[0].content()
116123
val part1 = decoded!!.parts[0]
@@ -127,10 +134,12 @@ class CodecTest {
127134
val aliceClient = fixtures.aliceClient!!
128135
val aliceConversation =
129136
aliceClient.conversations.newConversation(fixtures.bob.walletAddress)
130-
aliceConversation.send(
131-
content = 3.14,
132-
options = SendOptions(contentType = codec.contentType),
133-
)
137+
runBlocking {
138+
aliceConversation.send(
139+
content = 3.14,
140+
options = SendOptions(contentType = codec.contentType),
141+
)
142+
}
134143
val messages = aliceConversation.messages()
135144
assert(messages.isNotEmpty())
136145

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

+33-32
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import app.cash.turbine.test
55
import com.google.protobuf.kotlin.toByteString
66
import com.google.protobuf.kotlin.toByteStringUtf8
77
import kotlinx.coroutines.ExperimentalCoroutinesApi
8+
import kotlinx.coroutines.runBlocking
89
import org.junit.Assert
910
import org.junit.Assert.assertEquals
1011
import org.junit.Assert.assertFalse
@@ -173,8 +174,8 @@ class ConversationTest {
173174
val bobConversation = bobClient.conversations.newConversation(aliceWallet.address)
174175
val aliceConversation = aliceClient.conversations.newConversation(bobWallet.address)
175176

176-
bobConversation.send(content = "hey alice")
177-
bobConversation.send(content = "hey alice again")
177+
runBlocking { bobConversation.send(content = "hey alice") }
178+
runBlocking { bobConversation.send(content = "hey alice again") }
178179
val messages = aliceConversation.messages()
179180
assertEquals(2, messages.size)
180181
assertEquals("hey alice", messages[1].body)
@@ -192,7 +193,7 @@ class ConversationTest {
192193
bobWallet.address,
193194
InvitationV1ContextBuilder.buildFromConversation("hi"),
194195
)
195-
bobConversation.send(content = "hey alice")
196+
runBlocking { bobConversation.send(content = "hey alice") }
196197
val messages = aliceConversation.messages()
197198
assertEquals(1, messages.size)
198199
assertEquals("hey alice", messages[0].body)
@@ -268,10 +269,10 @@ class ConversationTest {
268269
fixtures.publishLegacyContact(client = aliceClient)
269270
val bobConversation = bobClient.conversations.newConversation(aliceWallet.address)
270271
val aliceConversation = aliceClient.conversations.newConversation(bobWallet.address)
271-
bobConversation.send(
272+
runBlocking { bobConversation.send(
272273
text = MutableList(1000) { "A" }.toString(),
273274
sendOptions = SendOptions(compression = EncodedContentCompression.GZIP),
274-
)
275+
) }
275276
val messages = aliceConversation.messages()
276277
assertEquals(1, messages.size)
277278
assertEquals(MutableList(1000) { "A" }.toString(), messages[0].content())
@@ -283,10 +284,10 @@ class ConversationTest {
283284
fixtures.publishLegacyContact(client = aliceClient)
284285
val bobConversation = bobClient.conversations.newConversation(aliceWallet.address)
285286
val aliceConversation = aliceClient.conversations.newConversation(bobWallet.address)
286-
bobConversation.send(
287+
runBlocking { bobConversation.send(
287288
content = MutableList(1000) { "A" }.toString(),
288289
options = SendOptions(compression = EncodedContentCompression.DEFLATE),
289-
)
290+
)}
290291
val messages = aliceConversation.messages()
291292
assertEquals(1, messages.size)
292293
assertEquals(MutableList(1000) { "A" }.toString(), messages[0].content())
@@ -302,10 +303,10 @@ class ConversationTest {
302303
bobWallet.address,
303304
InvitationV1ContextBuilder.buildFromConversation(conversationId = "hi"),
304305
)
305-
bobConversation.send(
306+
runBlocking { bobConversation.send(
306307
text = MutableList(1000) { "A" }.toString(),
307308
sendOptions = SendOptions(compression = EncodedContentCompression.GZIP),
308-
)
309+
)}
309310
val messages = aliceConversation.messages()
310311
assertEquals(1, messages.size)
311312
assertEquals(MutableList(1000) { "A" }.toString(), messages[0].body)
@@ -322,10 +323,10 @@ class ConversationTest {
322323
bobWallet.address,
323324
InvitationV1ContextBuilder.buildFromConversation(conversationId = "hi"),
324325
)
325-
bobConversation.send(
326+
runBlocking { bobConversation.send(
326327
content = MutableList(1000) { "A" }.toString(),
327328
options = SendOptions(compression = EncodedContentCompression.DEFLATE),
328-
)
329+
)}
329330
val messages = aliceConversation.messages()
330331
assertEquals(1, messages.size)
331332
assertEquals(MutableList(1000) { "A" }.toString(), messages[0].body)
@@ -401,9 +402,9 @@ class ConversationTest {
401402

402403
val date = Date()
403404
date.time = date.time - 1000000
404-
bobConversation.send(text = "hey alice 1", sentAt = date)
405-
bobConversation.send(text = "hey alice 2")
406-
bobConversation.send(text = "hey alice 3")
405+
runBlocking { bobConversation.send(text = "hey alice 1", sentAt = date) }
406+
runBlocking { bobConversation.send(text = "hey alice 2") }
407+
runBlocking {bobConversation.send(text = "hey alice 3") }
407408
val messages = aliceConversation.messages(limit = 1)
408409
assertEquals(1, messages.size)
409410
assertEquals("hey alice 3", messages[0].body)
@@ -422,9 +423,9 @@ class ConversationTest {
422423
)
423424
val date = Date()
424425
date.time = date.time - 1000000
425-
bobConversation.send(text = "hey alice 1", sentAt = date)
426-
bobConversation.send(text = "hey alice 2")
427-
bobConversation.send(text = "hey alice 3")
426+
runBlocking { bobConversation.send(text = "hey alice 1", sentAt = date) }
427+
runBlocking { bobConversation.send(text = "hey alice 2") }
428+
runBlocking { bobConversation.send(text = "hey alice 3") }
428429
val messages = aliceConversation.messages(limit = 1)
429430
assertEquals(1, messages.size)
430431
assertEquals("hey alice 3", messages[0].body)
@@ -445,9 +446,9 @@ class ConversationTest {
445446
val steveConversation =
446447
aliceClient.conversations.newConversation(fixtures.caro.walletAddress)
447448

448-
bobConversation.send(text = "hey alice 1")
449-
bobConversation.send(text = "hey alice 2")
450-
steveConversation.send(text = "hey alice 3")
449+
runBlocking { bobConversation.send(text = "hey alice 1") }
450+
runBlocking { bobConversation.send(text = "hey alice 2") }
451+
runBlocking { steveConversation.send(text = "hey alice 3") }
451452
val messages = aliceClient.conversations.listBatchMessages(
452453
listOf(
453454
Pair(steveConversation.topic, null),
@@ -469,9 +470,9 @@ class ConversationTest {
469470
val steveConversation =
470471
aliceClient.conversations.newConversation(fixtures.caro.walletAddress)
471472

472-
bobConversation.send(text = "hey alice 1")
473-
bobConversation.send(text = "hey alice 2")
474-
steveConversation.send(text = "hey alice 3")
473+
runBlocking { bobConversation.send(text = "hey alice 1") }
474+
runBlocking { bobConversation.send(text = "hey alice 2") }
475+
runBlocking { steveConversation.send(text = "hey alice 3") }
475476
val messages = aliceClient.conversations.listBatchDecryptedMessages(
476477
listOf(
477478
Pair(steveConversation.topic, null),
@@ -493,16 +494,16 @@ class ConversationTest {
493494
val steveConversation =
494495
aliceClient.conversations.newConversation(fixtures.caro.walletAddress)
495496

496-
bobConversation.send(text = "hey alice 1 bob")
497-
steveConversation.send(text = "hey alice 1 steve")
497+
runBlocking { bobConversation.send(text = "hey alice 1 bob") }
498+
runBlocking { steveConversation.send(text = "hey alice 1 steve") }
498499

499500
Thread.sleep(100)
500501
val date = Date()
501502

502-
bobConversation.send(text = "hey alice 2 bob")
503-
bobConversation.send(text = "hey alice 3 bob")
504-
steveConversation.send(text = "hey alice 2 steve")
505-
steveConversation.send(text = "hey alice 3 steve")
503+
runBlocking { bobConversation.send(text = "hey alice 2 bob") }
504+
runBlocking { bobConversation.send(text = "hey alice 3 bob") }
505+
runBlocking { steveConversation.send(text = "hey alice 2 steve") }
506+
runBlocking { steveConversation.send(text = "hey alice 3 steve") }
506507

507508
val messages = aliceClient.conversations.listBatchMessages(
508509
listOf(
@@ -753,7 +754,7 @@ class ConversationTest {
753754
val bobConversation = bobClient.conversations.newConversation(aliceWallet.address)
754755
val aliceConversation = aliceClient.conversations.newConversation(bobWallet.address)
755756
val encodedContent = TextCodec().encode(content = "hi")
756-
bobConversation.send(encodedContent = encodedContent)
757+
runBlocking { bobConversation.send(encodedContent = encodedContent) }
757758
val messages = aliceConversation.messages()
758759
assertEquals(1, messages.size)
759760
assertEquals("hi", messages[0].content())
@@ -763,7 +764,7 @@ class ConversationTest {
763764
fun testCanSendEncodedContentV2Message() {
764765
val bobConversation = bobClient.conversations.newConversation(aliceWallet.address)
765766
val encodedContent = TextCodec().encode(content = "hi")
766-
bobConversation.send(encodedContent = encodedContent)
767+
runBlocking { bobConversation.send(encodedContent = encodedContent) }
767768
val messages = bobConversation.messages()
768769
assertEquals(1, messages.size)
769770
assertEquals("hi", messages[0].content())
@@ -821,7 +822,7 @@ class ConversationTest {
821822
// Conversations you receive should start as unknown
822823
assertTrue(isUnknown)
823824

824-
aliceConversation.send(content = "hey bob")
825+
runBlocking { aliceConversation.send(content = "hey bob") }
825826
aliceClient.contacts.refreshConsentList()
826827
val isNowAllowed = aliceConversation.consentState() == ConsentState.ALLOWED
827828

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
44
import kotlinx.coroutines.CoroutineScope
55
import kotlinx.coroutines.Dispatchers
66
import kotlinx.coroutines.launch
7+
import kotlinx.coroutines.runBlocking
78
import org.junit.Assert.assertEquals
89
import org.junit.Ignore
910
import org.junit.Test
@@ -101,7 +102,7 @@ class ConversationsTest {
101102
sleep(2500)
102103

103104
for (i in 0 until 5) {
104-
boConversation.send(text = "Message $i")
105+
runBlocking { boConversation.send(text = "Message $i") }
105106
sleep(1000)
106107
}
107108
assertEquals(allMessages.size, 5)
@@ -112,7 +113,7 @@ class ConversationsTest {
112113
sleep(2500)
113114

114115
for (i in 0 until 5) {
115-
caroConversation.send(text = "Message $i")
116+
runBlocking { caroConversation.send(text = "Message $i") }
116117
sleep(1000)
117118
}
118119

@@ -131,7 +132,7 @@ class ConversationsTest {
131132
sleep(2500)
132133

133134
for (i in 0 until 5) {
134-
boConversation.send(text = "Message $i")
135+
runBlocking { boConversation.send(text = "Message $i") }
135136
sleep(1000)
136137
}
137138

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,8 @@ class GroupTest {
280280
@Test
281281
fun testGroupStartsWithAllowedState() {
282282
val group = boClient.conversations.newGroup(listOf(alix.walletAddress))
283-
group.send("howdy")
284-
group.send("gm")
283+
runBlocking { group.send("howdy") }
284+
runBlocking { group.send("gm") }
285285
runBlocking { group.sync() }
286286
assert(boClient.contacts.isGroupAllowed(group.id))
287287
assertEquals(boClient.contacts.consentList.groupState(group.id), ConsentState.ALLOWED)
@@ -290,8 +290,8 @@ class GroupTest {
290290
@Test
291291
fun testCanSendMessageToGroup() {
292292
val group = boClient.conversations.newGroup(listOf(alix.walletAddress))
293-
group.send("howdy")
294-
group.send("gm")
293+
runBlocking { group.send("howdy") }
294+
runBlocking { group.send("gm") }
295295
runBlocking { group.sync() }
296296
assertEquals(group.messages().first().body, "gm")
297297
assertEquals(group.messages().size, 3)
@@ -308,7 +308,7 @@ class GroupTest {
308308
Client.register(codec = ReactionCodec())
309309

310310
val group = boClient.conversations.newGroup(listOf(alix.walletAddress))
311-
group.send("gm")
311+
runBlocking { group.send("gm") }
312312
runBlocking { group.sync() }
313313
val messageToReact = group.messages()[0]
314314

@@ -319,7 +319,7 @@ class GroupTest {
319319
schema = ReactionSchema.Unicode
320320
)
321321

322-
group.send(content = reaction, options = SendOptions(contentType = ContentTypeReaction))
322+
runBlocking { group.send(content = reaction, options = SendOptions(contentType = ContentTypeReaction)) }
323323
runBlocking { group.sync() }
324324

325325
val messages = group.messages()

0 commit comments

Comments
 (0)