fix tests

This commit is contained in:
Andre Staltz 2023-12-21 11:20:32 +02:00
parent b0cfedbb00
commit 6d7d31f878
No known key found for this signature in database
GPG Key ID: 9EDE23EA7E8A4890
2 changed files with 8 additions and 8 deletions

View File

@ -36,8 +36,8 @@ test('Cleanup is scheduled automatically', async (t) => {
alice.goals.set(postFeedID, 'newest-3') alice.goals.set(postFeedID, 'newest-3')
assert('alice set a goal for newest-3 of post feed') assert('alice set a goal for newest-3 of post feed')
alice.gc.start(4 * 1024), // 4kB, approximately 8 messages alice.gc.start(4 * 1024) // 4kB, approximately 8 messages
await p(setTimeout)(3000) await p(setTimeout)(3000)
assert.deepEqual( assert.deepEqual(
getTexts([...alice.db.msgs()]), getTexts([...alice.db.msgs()]),
@ -93,7 +93,6 @@ test('Compaction is scheduled automatically', async (t) => {
alice.goals.set(alice.db.feed.getID(aliceID, 'post4'), 'all') alice.goals.set(alice.db.feed.getID(aliceID, 'post4'), 'all')
alice.gc.start(6 * 1024) // 6kB, approximately 12 messages alice.gc.start(6 * 1024) // 6kB, approximately 12 messages
await p(setTimeout)(3000) await p(setTimeout)(3000)
assert.deepEqual( assert.deepEqual(

View File

@ -1,19 +1,20 @@
const os = require('node:os') const OS = require('node:os')
const path = require('node:path') const Path = require('node:path')
const rimraf = require('rimraf') const rimraf = require('rimraf')
const caps = require('ppppp-caps') const caps = require('ppppp-caps')
const Keypair = require('ppppp-keypair') const Keypair = require('ppppp-keypair')
function createPeer(opts) { function createPeer(opts) {
if (opts.name) { if (opts.name) {
opts.path ??= path.join(os.tmpdir(), 'ppppp-gc-' + opts.name) const tmp = OS.tmpdir()
opts.db ??= {path: Path.join(tmp, `ppppp-gc-${opts.name}-${Date.now()}`)}
opts.keypair ??= Keypair.generate('ed25519', opts.name) opts.keypair ??= Keypair.generate('ed25519', opts.name)
opts.name = undefined opts.name = undefined
} }
if (!opts.path) throw new Error('need opts.path in createPeer()') if (!opts.db.path) throw new Error('need opts.db.path in createPeer()')
if (!opts.keypair) throw new Error('need opts.keypair in createPeer()') if (!opts.keypair) throw new Error('need opts.keypair in createPeer()')
rimraf.sync(opts.path) rimraf.sync(opts.db.path)
return require('secret-stack/bare')() return require('secret-stack/bare')()
.use(require('secret-stack/plugins/net')) .use(require('secret-stack/plugins/net'))
.use(require('secret-handshake-ext/secret-stack')) .use(require('secret-handshake-ext/secret-stack'))