Skip to content

Commit 125d1ac

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

File tree

12 files changed

+493
-519
lines changed

12 files changed

+493
-519
lines changed

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

+4-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ 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
65
import org.junit.Assert.assertEquals
76
import org.junit.Test
87
import org.junit.runner.RunWith
@@ -28,12 +27,10 @@ class AttachmentTest {
2827
val aliceConversation =
2928
aliceClient.conversations.newConversation(fixtures.bob.walletAddress)
3029

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

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

+16-25
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ 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
65
import org.junit.Assert.assertEquals
76
import org.junit.Assert.assertTrue
87
import org.junit.Test
@@ -61,12 +60,10 @@ class CodecTest {
6160
val aliceClient = fixtures.aliceClient
6261
val aliceConversation =
6362
aliceClient.conversations.newConversation(fixtures.bob.walletAddress)
64-
runBlocking {
65-
aliceConversation.send(
66-
content = 3.14,
67-
options = SendOptions(contentType = NumberCodec().contentType),
68-
)
69-
}
63+
aliceConversation.send(
64+
content = 3.14,
65+
options = SendOptions(contentType = NumberCodec().contentType),
66+
)
7067
val messages = aliceConversation.messages()
7168
assertEquals(messages.size, 1)
7269
if (messages.size == 1) {
@@ -85,12 +82,10 @@ class CodecTest {
8582
aliceClient.conversations.newConversation(fixtures.bob.walletAddress)
8683
val textContent = TextCodec().encode(content = "hiya")
8784
val source = DecodedComposite(encodedContent = textContent)
88-
runBlocking {
89-
aliceConversation.send(
90-
content = source,
91-
options = SendOptions(contentType = CompositeCodec().contentType),
92-
)
93-
}
85+
aliceConversation.send(
86+
content = source,
87+
options = SendOptions(contentType = CompositeCodec().contentType),
88+
)
9489
val messages = aliceConversation.messages()
9590
val decoded: DecodedComposite? = messages[0].content()
9691
assertEquals("hiya", decoded?.content())
@@ -112,12 +107,10 @@ class CodecTest {
112107
DecodedComposite(parts = listOf(DecodedComposite(encodedContent = numberContent))),
113108
),
114109
)
115-
runBlocking {
116-
aliceConversation.send(
117-
content = source,
118-
options = SendOptions(contentType = CompositeCodec().contentType),
119-
)
120-
}
110+
aliceConversation.send(
111+
content = source,
112+
options = SendOptions(contentType = CompositeCodec().contentType),
113+
)
121114
val messages = aliceConversation.messages()
122115
val decoded: DecodedComposite? = messages[0].content()
123116
val part1 = decoded!!.parts[0]
@@ -134,12 +127,10 @@ class CodecTest {
134127
val aliceClient = fixtures.aliceClient!!
135128
val aliceConversation =
136129
aliceClient.conversations.newConversation(fixtures.bob.walletAddress)
137-
runBlocking {
138-
aliceConversation.send(
139-
content = 3.14,
140-
options = SendOptions(contentType = codec.contentType),
141-
)
142-
}
130+
aliceConversation.send(
131+
content = 3.14,
132+
options = SendOptions(contentType = codec.contentType),
133+
)
143134
val messages = aliceConversation.messages()
144135
assert(messages.isNotEmpty())
145136

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

+32-33
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ 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
98
import org.junit.Assert
109
import org.junit.Assert.assertEquals
1110
import org.junit.Assert.assertFalse
@@ -174,8 +173,8 @@ class ConversationTest {
174173
val bobConversation = bobClient.conversations.newConversation(aliceWallet.address)
175174
val aliceConversation = aliceClient.conversations.newConversation(bobWallet.address)
176175

177-
runBlocking { bobConversation.send(content = "hey alice") }
178-
runBlocking { bobConversation.send(content = "hey alice again") }
176+
bobConversation.send(content = "hey alice")
177+
bobConversation.send(content = "hey alice again")
179178
val messages = aliceConversation.messages()
180179
assertEquals(2, messages.size)
181180
assertEquals("hey alice", messages[1].body)
@@ -193,7 +192,7 @@ class ConversationTest {
193192
bobWallet.address,
194193
InvitationV1ContextBuilder.buildFromConversation("hi"),
195194
)
196-
runBlocking { bobConversation.send(content = "hey alice") }
195+
bobConversation.send(content = "hey alice")
197196
val messages = aliceConversation.messages()
198197
assertEquals(1, messages.size)
199198
assertEquals("hey alice", messages[0].body)
@@ -269,10 +268,10 @@ class ConversationTest {
269268
fixtures.publishLegacyContact(client = aliceClient)
270269
val bobConversation = bobClient.conversations.newConversation(aliceWallet.address)
271270
val aliceConversation = aliceClient.conversations.newConversation(bobWallet.address)
272-
runBlocking { bobConversation.send(
271+
bobConversation.send(
273272
text = MutableList(1000) { "A" }.toString(),
274273
sendOptions = SendOptions(compression = EncodedContentCompression.GZIP),
275-
) }
274+
)
276275
val messages = aliceConversation.messages()
277276
assertEquals(1, messages.size)
278277
assertEquals(MutableList(1000) { "A" }.toString(), messages[0].content())
@@ -284,10 +283,10 @@ class ConversationTest {
284283
fixtures.publishLegacyContact(client = aliceClient)
285284
val bobConversation = bobClient.conversations.newConversation(aliceWallet.address)
286285
val aliceConversation = aliceClient.conversations.newConversation(bobWallet.address)
287-
runBlocking { bobConversation.send(
286+
bobConversation.send(
288287
content = MutableList(1000) { "A" }.toString(),
289288
options = SendOptions(compression = EncodedContentCompression.DEFLATE),
290-
)}
289+
)
291290
val messages = aliceConversation.messages()
292291
assertEquals(1, messages.size)
293292
assertEquals(MutableList(1000) { "A" }.toString(), messages[0].content())
@@ -303,10 +302,10 @@ class ConversationTest {
303302
bobWallet.address,
304303
InvitationV1ContextBuilder.buildFromConversation(conversationId = "hi"),
305304
)
306-
runBlocking { bobConversation.send(
305+
bobConversation.send(
307306
text = MutableList(1000) { "A" }.toString(),
308307
sendOptions = SendOptions(compression = EncodedContentCompression.GZIP),
309-
)}
308+
)
310309
val messages = aliceConversation.messages()
311310
assertEquals(1, messages.size)
312311
assertEquals(MutableList(1000) { "A" }.toString(), messages[0].body)
@@ -323,10 +322,10 @@ class ConversationTest {
323322
bobWallet.address,
324323
InvitationV1ContextBuilder.buildFromConversation(conversationId = "hi"),
325324
)
326-
runBlocking { bobConversation.send(
325+
bobConversation.send(
327326
content = MutableList(1000) { "A" }.toString(),
328327
options = SendOptions(compression = EncodedContentCompression.DEFLATE),
329-
)}
328+
)
330329
val messages = aliceConversation.messages()
331330
assertEquals(1, messages.size)
332331
assertEquals(MutableList(1000) { "A" }.toString(), messages[0].body)
@@ -402,9 +401,9 @@ class ConversationTest {
402401

403402
val date = Date()
404403
date.time = date.time - 1000000
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") }
404+
bobConversation.send(text = "hey alice 1", sentAt = date)
405+
bobConversation.send(text = "hey alice 2")
406+
bobConversation.send(text = "hey alice 3")
408407
val messages = aliceConversation.messages(limit = 1)
409408
assertEquals(1, messages.size)
410409
assertEquals("hey alice 3", messages[0].body)
@@ -423,9 +422,9 @@ class ConversationTest {
423422
)
424423
val date = Date()
425424
date.time = date.time - 1000000
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") }
425+
bobConversation.send(text = "hey alice 1", sentAt = date)
426+
bobConversation.send(text = "hey alice 2")
427+
bobConversation.send(text = "hey alice 3")
429428
val messages = aliceConversation.messages(limit = 1)
430429
assertEquals(1, messages.size)
431430
assertEquals("hey alice 3", messages[0].body)
@@ -446,9 +445,9 @@ class ConversationTest {
446445
val steveConversation =
447446
aliceClient.conversations.newConversation(fixtures.caro.walletAddress)
448447

449-
runBlocking { bobConversation.send(text = "hey alice 1") }
450-
runBlocking { bobConversation.send(text = "hey alice 2") }
451-
runBlocking { steveConversation.send(text = "hey alice 3") }
448+
bobConversation.send(text = "hey alice 1")
449+
bobConversation.send(text = "hey alice 2")
450+
steveConversation.send(text = "hey alice 3")
452451
val messages = aliceClient.conversations.listBatchMessages(
453452
listOf(
454453
Pair(steveConversation.topic, null),
@@ -470,9 +469,9 @@ class ConversationTest {
470469
val steveConversation =
471470
aliceClient.conversations.newConversation(fixtures.caro.walletAddress)
472471

473-
runBlocking { bobConversation.send(text = "hey alice 1") }
474-
runBlocking { bobConversation.send(text = "hey alice 2") }
475-
runBlocking { steveConversation.send(text = "hey alice 3") }
472+
bobConversation.send(text = "hey alice 1")
473+
bobConversation.send(text = "hey alice 2")
474+
steveConversation.send(text = "hey alice 3")
476475
val messages = aliceClient.conversations.listBatchDecryptedMessages(
477476
listOf(
478477
Pair(steveConversation.topic, null),
@@ -494,16 +493,16 @@ class ConversationTest {
494493
val steveConversation =
495494
aliceClient.conversations.newConversation(fixtures.caro.walletAddress)
496495

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

500499
Thread.sleep(100)
501500
val date = Date()
502501

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") }
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")
507506

508507
val messages = aliceClient.conversations.listBatchMessages(
509508
listOf(
@@ -754,7 +753,7 @@ class ConversationTest {
754753
val bobConversation = bobClient.conversations.newConversation(aliceWallet.address)
755754
val aliceConversation = aliceClient.conversations.newConversation(bobWallet.address)
756755
val encodedContent = TextCodec().encode(content = "hi")
757-
runBlocking { bobConversation.send(encodedContent = encodedContent) }
756+
bobConversation.send(encodedContent = encodedContent)
758757
val messages = aliceConversation.messages()
759758
assertEquals(1, messages.size)
760759
assertEquals("hi", messages[0].content())
@@ -764,7 +763,7 @@ class ConversationTest {
764763
fun testCanSendEncodedContentV2Message() {
765764
val bobConversation = bobClient.conversations.newConversation(aliceWallet.address)
766765
val encodedContent = TextCodec().encode(content = "hi")
767-
runBlocking { bobConversation.send(encodedContent = encodedContent) }
766+
bobConversation.send(encodedContent = encodedContent)
768767
val messages = bobConversation.messages()
769768
assertEquals(1, messages.size)
770769
assertEquals("hi", messages[0].content())
@@ -822,7 +821,7 @@ class ConversationTest {
822821
// Conversations you receive should start as unknown
823822
assertTrue(isUnknown)
824823

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

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

+3-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ 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
87
import org.junit.Assert.assertEquals
98
import org.junit.Ignore
109
import org.junit.Test
@@ -102,7 +101,7 @@ class ConversationsTest {
102101
sleep(2500)
103102

104103
for (i in 0 until 5) {
105-
runBlocking { boConversation.send(text = "Message $i") }
104+
boConversation.send(text = "Message $i")
106105
sleep(1000)
107106
}
108107
assertEquals(allMessages.size, 5)
@@ -113,7 +112,7 @@ class ConversationsTest {
113112
sleep(2500)
114113

115114
for (i in 0 until 5) {
116-
runBlocking { caroConversation.send(text = "Message $i") }
115+
caroConversation.send(text = "Message $i")
117116
sleep(1000)
118117
}
119118

@@ -132,7 +131,7 @@ class ConversationsTest {
132131
sleep(2500)
133132

134133
for (i in 0 until 5) {
135-
runBlocking { boConversation.send(text = "Message $i") }
134+
boConversation.send(text = "Message $i")
136135
sleep(1000)
137136
}
138137

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-
runBlocking { group.send("howdy") }
284-
runBlocking { group.send("gm") }
283+
group.send("howdy")
284+
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-
runBlocking { group.send("howdy") }
294-
runBlocking { group.send("gm") }
293+
group.send("howdy")
294+
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-
runBlocking { group.send("gm") }
311+
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-
runBlocking { group.send(content = reaction, options = SendOptions(contentType = ContentTypeReaction)) }
322+
group.send(content = reaction, options = SendOptions(contentType = ContentTypeReaction))
323323
runBlocking { group.sync() }
324324

325325
val messages = group.messages()

0 commit comments

Comments
 (0)