Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test that deleteFeed and compact works #359

Merged
merged 1 commit into from
Jun 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"operators/*.js"
],
"dependencies": {
"async-append-only-log": "^4.2.2",
"async-append-only-log": "^4.2.4",
"atomic-file-rw": "^0.2.1",
"binary-search-bounds": "^2.0.4",
"bipf": "^1.5.4",
Expand Down
101 changes: 101 additions & 0 deletions test/delete-feed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// SPDX-FileCopyrightText: 2022 Andre 'Staltz' Medeiros <[email protected]>
//
// SPDX-License-Identifier: CC0-1.0

const test = require('tape')
const ssbKeys = require('ssb-keys')
const path = require('path')
const rimraf = require('rimraf')
const mkdirp = require('mkdirp')
const pull = require('pull-stream')
const pify = require('util').promisify
const SecretStack = require('secret-stack')
const caps = require('ssb-caps')
const generateFixture = require('ssb-fixtures')
const fs = require('fs')
const { where, author, toPromise } = require('../operators')

const dir = '/tmp/ssb-db2-delete-feed-compact'

rimraf.sync(dir)
mkdirp.sync(dir)

const TOTAL = 100

test('generate fixture with flumelog-offset', (t) => {
generateFixture({
outputDir: dir,
seed: 'migrate',
messages: TOTAL,
authors: 5,
slim: true,
followGraph: true,
}).then(() => {
t.true(
fs.existsSync(path.join(dir, 'flume', 'log.offset')),
'log.offset was created'
)
t.end()
})
})

test('delete a feed and then compact', async (t) => {
const keys = ssbKeys.loadOrCreateSync(path.join(dir, 'secret'))
const sbot = SecretStack({ appKey: caps.shs })
.use(require('../'))
.call(null, {
keys,
path: dir,
db2: { dangerouslyKillFlumeWhenMigrated: true },
})

await new Promise((resolve, reject) => {
sbot.db2migrate.start()
pull(
sbot.db2migrate.progress(),
pull.take(1),
pull.collect((err) => {
if (err) reject(err)
else resolve()
})
)
})

const badPerson = '@a5URnr0bEtVFmNxQu/JwQ5JsfEl+HAPz5ethL+I1CCA=.ed25519'
t.notEqual(sbot.id, badPerson, 'I am not the bad person')

await new Promise((resolve) => {
sbot.db.getStatus()((stats) => {
if (stats.log > 0 && stats.progress === 1) {
resolve()
return false // abort listening to status
}
})
})
t.pass('status updated')

const msgsBad1 = await sbot.db.query(where(author(badPerson)), toPromise())
t.equals(msgsBad1.length, 18, 'bad person has published some messages')

await pify(sbot.db.deleteFeed)(badPerson)
t.pass('deleted bad person from my log')

await pify(sbot.db.compact)()
t.pass('compacted')

await new Promise((resolve) => {
sbot.db.getStatus()((stats) => {
if (stats.log > 0 && stats.progress === 1) {
resolve()
return false // abort listening to status
}
})
})
t.pass('status updated')

const msgsBad2 = await sbot.db.query(where(author(badPerson)), toPromise())
t.equals(msgsBad2.length, 0, 'zero messages by bad person')

await pify(sbot.close)(true)
t.end()
})