Skip to content

Commit

Permalink
Merge pull request #307 from xmtp/kele/stream-tests
Browse files Browse the repository at this point in the history
fix: Streaming bug
  • Loading branch information
nplasterer authored Mar 13, 2024
2 parents f7c3f55 + 7a4552d commit ae6d3c4
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 8 deletions.
14 changes: 7 additions & 7 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ PODS:
- hermes-engine/Pre-built (= 0.71.14)
- hermes-engine/Pre-built (0.71.14)
- libevent (2.1.12)
- LibXMTP (0.4.3-beta1)
- LibXMTP (0.4.3-beta2)
- Logging (1.0.0)
- MessagePacker (0.4.7)
- MMKV (1.3.3):
Expand Down Expand Up @@ -445,16 +445,16 @@ PODS:
- GenericJSON (~> 2.0)
- Logging (~> 1.0.0)
- secp256k1.swift (~> 0.1)
- XMTP (0.9.0):
- XMTP (0.9.1):
- Connect-Swift (= 0.3.0)
- GzipSwift
- LibXMTP (= 0.4.3-beta1)
- LibXMTP (= 0.4.3-beta2)
- web3.swift
- XMTPReactNative (0.1.0):
- ExpoModulesCore
- MessagePacker
- secp256k1.swift
- XMTP (= 0.9.0)
- XMTP (= 0.9.1)
- Yoga (1.14.0)

DEPENDENCIES:
Expand Down Expand Up @@ -701,7 +701,7 @@ SPEC CHECKSUMS:
GzipSwift: 893f3e48e597a1a4f62fafcb6514220fcf8287fa
hermes-engine: d7cc127932c89c53374452d6f93473f1970d8e88
libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913
LibXMTP: ddfcde5d4c9b3baa34b038956a7aad46e1da6391
LibXMTP: ef1e7d04de6b7f0cb88f7678be44bb6329263f6c
Logging: 9ef4ecb546ad3169398d5a723bc9bea1c46bef26
MessagePacker: ab2fe250e86ea7aedd1a9ee47a37083edd41fd02
MMKV: f902fb6719da13c2ab0965233d8963a59416f911
Expand Down Expand Up @@ -751,8 +751,8 @@ SPEC CHECKSUMS:
secp256k1.swift: a7e7a214f6db6ce5db32cc6b2b45e5c4dd633634
SwiftProtobuf: b02b5075dcf60c9f5f403000b3b0c202a11b6ae1
web3.swift: 2263d1e12e121b2c42ffb63a5a7beb1acaf33959
XMTP: f539ad61202ae67ed813f2dd756875c31ce9a677
XMTPReactNative: 845b4760d768d2971e478c46f80d4302de90b6a4
XMTP: 1d6bbf66833dc71763de3345f63801dbc6c6de27
XMTPReactNative: 28a3ff58d411efe05cf6ee4429b315e5e3bd169a
Yoga: e71803b4c1fff832ccf9b92541e00f9b873119b9

PODFILE CHECKSUM: 95d6ace79946933ecf80684613842ee553dd76a2
Expand Down
105 changes: 105 additions & 0 deletions example/src/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ function delayToPropogate(): Promise<void> {
return new Promise((r) => setTimeout(r, 100))
}

function sleep(ms: number) {
return new Promise((resolve) => setTimeout(resolve, ms))
}

const hkdfNoSalt = new ArrayBuffer(0)

async function hkdfHmacKey(
Expand Down Expand Up @@ -621,6 +625,48 @@ test('can stream messages', async () => {
return true
})

test('can stream conversations with delay', async () => {
const bo = await Client.createRandom({ env: 'dev' })
await delayToPropogate()
const alix = await Client.createRandom({ env: 'dev' })
await delayToPropogate()

const allConvos: Conversation<any>[] = []
await alix.conversations.stream(async (convo) => {
allConvos.push(convo)
})

await bo.conversations.newConversation(alix.address)
await delayToPropogate()

await bo.conversations.newConversation(alix.address, {
conversationID: 'convo-2',
metadata: {},
})
await delayToPropogate()

assert(
allConvos.length === 2,
'Unexpected all convos count ' + allConvos.length
)

await sleep(15000)

await bo.conversations.newConversation(alix.address, {
conversationID: 'convo-3',
metadata: {},
})
await delayToPropogate()

assert(
allConvos.length === 3,
'Unexpected all convos count ' + allConvos.length
)

alix.conversations.cancelStream()
return true
})

test('remote attachments should work', async () => {
const alice = await Client.createRandom({
env: 'local',
Expand Down Expand Up @@ -802,6 +848,65 @@ test('can stream all messages', async () => {
return true
})

test('can stream all msgs with delay', async () => {
const bo = await Client.createRandom({ env: 'dev' })
await delayToPropogate()
const alix = await Client.createRandom({ env: 'dev' })
await delayToPropogate()

// Record message stream across all conversations
const allMessages: DecodedMessage[] = []
await alix.conversations.streamAllMessages(async (message) => {
allMessages.push(message)
})

// Start Bob starts a new conversation.
const boConvo = await bo.conversations.newConversation(alix.address)
await delayToPropogate()

for (let i = 0; i < 5; i++) {
await boConvo.send({ text: `Message ${i}` })
await delayToPropogate()
}

assert(
allMessages.length === 5,
'Unexpected all messages count ' + allMessages.length
)

await sleep(15000)
// Starts a new conversation.
const caro = await Client.createRandom({ env: 'dev' })
const caroConvo = await caro.conversations.newConversation(alix.address)
await delayToPropogate()

for (let i = 0; i < 5; i++) {
await caroConvo.send({ text: `Message ${i}` })
await delayToPropogate()
}

assert(
allMessages.length === 10,
'Unexpected all messages count ' + allMessages.length
)

await sleep(15000)

for (let i = 0; i < 5; i++) {
await boConvo.send({ text: `Message ${i}` })
await delayToPropogate()
}

assert(
allMessages.length === 15,
'Unexpected all messages count ' + allMessages.length
)

alix.conversations.cancelStreamAllMessages()

return true
})

test('canManagePreferences', async () => {
const bo = await Client.createRandom({ env: 'local' })
const alix = await Client.createRandom({ env: 'local' })
Expand Down
2 changes: 1 addition & 1 deletion ios/XMTPReactNative.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ Pod::Spec.new do |s|
s.source_files = "**/*.{h,m,swift}"
s.dependency 'secp256k1.swift'
s.dependency "MessagePacker"
s.dependency "XMTP", "= 0.9.0"
s.dependency "XMTP", "= 0.9.1"
end

0 comments on commit ae6d3c4

Please sign in to comment.