mirror of https://codeberg.org/pzp/pzp-gc.git
start() will automatically stop()
This commit is contained in:
parent
6d7d31f878
commit
d596754bd1
|
@ -214,6 +214,7 @@ function initGC(peer, config) {
|
||||||
* @param {number?} maxLogBytes
|
* @param {number?} maxLogBytes
|
||||||
*/
|
*/
|
||||||
function start(maxLogBytes) {
|
function start(maxLogBytes) {
|
||||||
|
stop()
|
||||||
const actualMaxLogBytes = maxLogBytes ?? config.gc?.maxLogBytes ?? null
|
const actualMaxLogBytes = maxLogBytes ?? config.gc?.maxLogBytes ?? null
|
||||||
// prettier-ignore
|
// prettier-ignore
|
||||||
if (!actualMaxLogBytes) throw new Error('gc plugin requires maxLogBytes via start() argument or config.gc.maxLogBytes')
|
if (!actualMaxLogBytes) throw new Error('gc plugin requires maxLogBytes via start() argument or config.gc.maxLogBytes')
|
||||||
|
|
|
@ -103,3 +103,46 @@ test('Compaction is scheduled automatically', async (t) => {
|
||||||
|
|
||||||
await p(alice.close)(true)
|
await p(alice.close)(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('start() will automatically stop()', async (t) => {
|
||||||
|
const alice = createPeer({ name: 'alice' })
|
||||||
|
await alice.db.loaded()
|
||||||
|
|
||||||
|
// Alice creates her own account
|
||||||
|
const aliceID = await p(alice.db.account.create)({
|
||||||
|
subdomain: 'account',
|
||||||
|
_nonce: 'alice',
|
||||||
|
})
|
||||||
|
|
||||||
|
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')
|
||||||
|
|
||||||
|
alice.gc.start(40 * 1024) // 40kB
|
||||||
|
|
||||||
|
for (let i = 0; i < 5; i++) {
|
||||||
|
await p(alice.db.feed.publish)({
|
||||||
|
account: aliceID,
|
||||||
|
domain: 'post',
|
||||||
|
data: { text: 'A' + i },
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.deepEqual(
|
||||||
|
getTexts([...alice.db.msgs()]),
|
||||||
|
['A0', 'A1', 'A2', 'A3', 'A4'],
|
||||||
|
'alice has the whole feed'
|
||||||
|
)
|
||||||
|
|
||||||
|
alice.gc.start(4 * 1024) // 4kB, approximately 8 messages
|
||||||
|
await p(setTimeout)(3000)
|
||||||
|
|
||||||
|
assert.deepEqual(
|
||||||
|
getTexts([...alice.db.msgs()]),
|
||||||
|
['A2', 'A3', 'A4'],
|
||||||
|
'alice has only latest 3 msgs in the feed'
|
||||||
|
)
|
||||||
|
|
||||||
|
await p(alice.close)(true)
|
||||||
|
})
|
||||||
|
|
Loading…
Reference in New Issue