mirror of https://codeberg.org/pzp/pzp-gc.git
test that feed holes are also cleaned up
This commit is contained in:
parent
34cf50b320
commit
c7d743f589
|
@ -0,0 +1,66 @@
|
|||
const test = require('node:test')
|
||||
const assert = require('node:assert')
|
||||
const p = require('node:util').promisify
|
||||
const { createPeer } = require('./util')
|
||||
|
||||
function getTexts(msgs) {
|
||||
return msgs.filter((msg) => msg.data?.text).map((msg) => msg.data.text)
|
||||
}
|
||||
|
||||
test('feed holes', async (t) => {
|
||||
const alice = createPeer({
|
||||
name: 'alice',
|
||||
gc: { maxLogBytes: 100 * 1024 * 1024 },
|
||||
})
|
||||
|
||||
await alice.db.loaded()
|
||||
|
||||
// Alice creates her own account
|
||||
const aliceID = await p(alice.db.account.create)({
|
||||
domain: 'account',
|
||||
_nonce: 'alice',
|
||||
})
|
||||
|
||||
const posts = []
|
||||
for (let i = 0; i < 10; i++) {
|
||||
const rec = await p(alice.db.feed.publish)({
|
||||
account: aliceID,
|
||||
domain: 'post',
|
||||
data: { text: 'A' + i },
|
||||
})
|
||||
posts.push(rec.id)
|
||||
}
|
||||
|
||||
assert.deepEqual(
|
||||
getTexts([...alice.db.msgs()]),
|
||||
['A0', 'A1', 'A2', 'A3', 'A4', 'A5', 'A6', 'A7', 'A8', 'A9'],
|
||||
'alice has the whole feed'
|
||||
)
|
||||
|
||||
await p(alice.db.del)(posts[3])
|
||||
await p(alice.db.del)(posts[4])
|
||||
await p(alice.db.del)(posts[5])
|
||||
await p(alice.db.del)(posts[6])
|
||||
assert('alice deleted the middle part of the feed')
|
||||
|
||||
assert.deepEqual(
|
||||
getTexts([...alice.db.msgs()]),
|
||||
['A0', 'A1', 'A2', 'A7', 'A8', 'A9'],
|
||||
'alice has the beginning and the end of the feed'
|
||||
)
|
||||
|
||||
alice.goals.set(aliceID, 'all') // alice wants her account tangle
|
||||
const postFeedID = alice.db.feed.getID(aliceID, 'post')
|
||||
alice.goals.set(postFeedID, 'newest-3')
|
||||
assert('alice set a goal for newest-3 of post feed')
|
||||
|
||||
await p(alice.gc.forceImmediately)()
|
||||
|
||||
assert.deepEqual(
|
||||
getTexts([...alice.db.msgs()]),
|
||||
['A7', 'A8', 'A9'],
|
||||
'alice has only the end of the feed'
|
||||
)
|
||||
|
||||
await p(alice.close)(true)
|
||||
})
|
Loading…
Reference in New Issue