mirror of https://codeberg.org/pzp/pzp-sync.git
Start adding realtime test with 100 msgs
This commit is contained in:
parent
c1a5b0a9e2
commit
cbf12a5e8c
|
@ -167,3 +167,71 @@ test('sync feed msgs in realtime after the 9 rounds, reverse', async (t) => {
|
||||||
await p(alice.close)(true)
|
await p(alice.close)(true)
|
||||||
await p(bob.close)(true)
|
await p(bob.close)(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('create 100 messages in parallel that still manage to sync realtime', async (t) => {
|
||||||
|
const alice = createPeer({ name: 'alice' })
|
||||||
|
const bob = createPeer({ name: 'bob' })
|
||||||
|
|
||||||
|
await alice.db.loaded()
|
||||||
|
await bob.db.loaded()
|
||||||
|
|
||||||
|
const bobID = await p(bob.db.account.create)({
|
||||||
|
subdomain: 'account',
|
||||||
|
_nonce: 'bob',
|
||||||
|
})
|
||||||
|
|
||||||
|
const bobPostsID = bob.db.feed.getID(bobID, 'post')
|
||||||
|
|
||||||
|
{
|
||||||
|
const arr = (await flatten(alice.db.msgs()))
|
||||||
|
.filter((msg) => msg.metadata.account === bobID && msg.data)
|
||||||
|
.map((msg) => msg.data.text)
|
||||||
|
assert.deepEqual(arr, [], 'alice has no posts from bob')
|
||||||
|
}
|
||||||
|
|
||||||
|
bob.goals.set(bobPostsID, 'all')
|
||||||
|
alice.goals.set(bobPostsID, 'all')
|
||||||
|
|
||||||
|
const remoteBob = await p(alice.connect)(bob.getAddress())
|
||||||
|
assert('alice and bob connected')
|
||||||
|
|
||||||
|
alice.sync.start()
|
||||||
|
await p(setTimeout)(1000)
|
||||||
|
assert('sync!')
|
||||||
|
|
||||||
|
const n = 1
|
||||||
|
const hundred = []
|
||||||
|
for (let i = 0; i < n; i++) {
|
||||||
|
hundred.push(i)
|
||||||
|
}
|
||||||
|
await Promise.all(hundred.map(i => p(bob.db.feed.publish)({
|
||||||
|
account: bobID,
|
||||||
|
domain: 'post',
|
||||||
|
data: { text: `post nr ${i}` },
|
||||||
|
})))
|
||||||
|
assert('bob published 100 posts in parallel')
|
||||||
|
|
||||||
|
const bobMsgs = await flatten(bob.db.msgs())
|
||||||
|
// 1 for creating bob's account and 1 for the 'post' moot
|
||||||
|
assert.equal(bobMsgs.length, n + 2, "bob has all of his own messages")
|
||||||
|
|
||||||
|
let arr
|
||||||
|
// just waiting for them to arrive
|
||||||
|
for (let i = 0; i < 100; i++) {
|
||||||
|
arr = (await flatten(alice.db.msgs()))
|
||||||
|
//.filter((msg) => msg.metadata.account === bobID && msg.data)
|
||||||
|
.filter(msg => msg.domain === 'post')
|
||||||
|
.map((msg) => msg.data.text)
|
||||||
|
if (arr.length < n) {
|
||||||
|
await p(setTimeout)(100)
|
||||||
|
} else {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log('msgs', arr)
|
||||||
|
assert.equal(arr.length, n, `alice has ${arr.length} posts from bob`)
|
||||||
|
|
||||||
|
await p(remoteBob.close)(true)
|
||||||
|
await p(alice.close)(true)
|
||||||
|
await p(bob.close)(true)
|
||||||
|
})
|
Loading…
Reference in New Issue