mirror of https://codeberg.org/pzp/pzp-db.git
improve tests for del() and erase()
This commit is contained in:
parent
cfebe1f46c
commit
2b1de9bce7
|
@ -20,7 +20,10 @@ test('del()', async (t) => {
|
|||
|
||||
await peer.db.loaded()
|
||||
|
||||
const id = await p(peer.db.account.create)({ subdomain: 'person' })
|
||||
const id = await p(peer.db.account.create)({
|
||||
subdomain: 'person',
|
||||
_nonce: 'alice',
|
||||
})
|
||||
|
||||
const msgIDs = []
|
||||
for (let i = 0; i < 5; i++) {
|
||||
|
@ -45,6 +48,13 @@ test('del()', async (t) => {
|
|||
'msgs before the delete'
|
||||
)
|
||||
|
||||
const stats1 = await p(peer.db.log.stats)()
|
||||
assert.deepEqual(
|
||||
stats1,
|
||||
{ totalBytes: 3399, deletedBytes: 0 },
|
||||
'stats before delete and compact'
|
||||
)
|
||||
|
||||
await p(peer.db.del)(msgIDs[2])
|
||||
|
||||
const after = []
|
||||
|
@ -86,6 +96,13 @@ test('del()', async (t) => {
|
|||
)
|
||||
})
|
||||
|
||||
const stats2 = await p(log.stats)()
|
||||
assert.deepEqual(
|
||||
stats2,
|
||||
{ totalBytes: 2889, deletedBytes: 0 },
|
||||
'stats after delete and compact'
|
||||
)
|
||||
|
||||
assert.deepEqual(
|
||||
persistedMsgs
|
||||
.filter((msg) => msg.data && msg.metadata.account?.length > 4)
|
||||
|
|
|
@ -6,7 +6,6 @@ const p = require('node:util').promisify
|
|||
const rimraf = require('rimraf')
|
||||
const SecretStack = require('secret-stack')
|
||||
const Log = require('../lib/log')
|
||||
const push = require('push-stream')
|
||||
const caps = require('ppppp-caps')
|
||||
const Keypair = require('ppppp-keypair')
|
||||
|
||||
|
@ -21,7 +20,10 @@ test('erase()', async (t) => {
|
|||
|
||||
await peer.db.loaded()
|
||||
|
||||
const id = await p(peer.db.account.create)({ subdomain: 'person' })
|
||||
const id = await p(peer.db.account.create)({
|
||||
subdomain: 'person',
|
||||
_nonce: 'alice',
|
||||
})
|
||||
|
||||
const msgIDs = []
|
||||
for (let i = 0; i < 5; i++) {
|
||||
|
@ -32,6 +34,7 @@ test('erase()', async (t) => {
|
|||
})
|
||||
msgIDs.push(rec.id)
|
||||
}
|
||||
const SAVED_UPON_ERASE = '{"text":"m*"}'.length - 'null'.length
|
||||
|
||||
const before = []
|
||||
for (const msg of peer.db.msgs()) {
|
||||
|
@ -46,6 +49,14 @@ test('erase()', async (t) => {
|
|||
'5 msgs before the erase'
|
||||
)
|
||||
|
||||
const EXPECTED_TOTAL_BYTES = 3399
|
||||
const stats1 = await p(peer.db.log.stats)()
|
||||
assert.deepEqual(
|
||||
stats1,
|
||||
{ totalBytes: EXPECTED_TOTAL_BYTES, deletedBytes: 0 },
|
||||
'stats before erase and compact'
|
||||
)
|
||||
|
||||
await p(peer.db.erase)(msgIDs[2])
|
||||
|
||||
const after = []
|
||||
|
@ -103,6 +114,13 @@ test('erase()', async (t) => {
|
|||
}
|
||||
}
|
||||
|
||||
const stats2 = await p(log.stats)()
|
||||
assert.deepEqual(
|
||||
stats2,
|
||||
{ totalBytes: EXPECTED_TOTAL_BYTES - SAVED_UPON_ERASE, deletedBytes: 0 },
|
||||
'stats after erase and compact'
|
||||
)
|
||||
|
||||
assert.deepEqual(
|
||||
afterReopen,
|
||||
['m0', 'm1', 'm3', 'm4'],
|
||||
|
|
Loading…
Reference in New Issue