Skip to content

Commit

Permalink
failing test: bulk create adds messages to db in wrong order
Browse files Browse the repository at this point in the history
  • Loading branch information
mixmix committed Apr 11, 2024
1 parent 83927c0 commit 5cd23e2
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 5 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@
"ssb-caps": "1.1.0",
"ssb-db": "19.3.1",
"ssb-fixtures": "4.0.1",
"tap-arc": "^0.3.4",
"tape": "^5.2.2",
"tap-arc": "^1.2.2",
"tape": "^5.7.5",
"trammel": "~4.0.0"
},
"scripts": {
Expand Down
55 changes: 52 additions & 3 deletions test/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,16 @@ const bipf = require('bipf')
const mkdirp = require('mkdirp')
const SecretStack = require('secret-stack')
const caps = require('ssb-caps')
const { where, isDecrypted, toCallback } = require('../operators')
const pull = require('pull-stream')
const { promisify: p } = require('util')

const {
where,
type,
isDecrypted,
toCallback,
toPullStream,
} = require('../operators')

const dir = '/tmp/ssb-db2-create'

Expand All @@ -19,7 +28,7 @@ mkdirp.sync(dir)

const keys = ssbKeys.loadOrCreateSync(path.join(dir, 'secret'))

let sbot = SecretStack({ appKey: caps.shs })
const sbot = SecretStack({ appKey: caps.shs })
.use(require('../'))
.use(require('../compat/ebt'))
.use(require('ssb-bendy-butt'))
Expand All @@ -28,7 +37,7 @@ let sbot = SecretStack({ appKey: caps.shs })
keys,
path: dir,
})
let db = sbot.db
const db = sbot.db

test('create() classic', (t) => {
db.create(
Expand Down Expand Up @@ -85,6 +94,46 @@ test('create() classic "too big"', (t) => {
})
})

test('create() bulk, fast!', async (t) => {
const N = 4
const many = new Array(N).fill('').map(() => {
return { type: 'counter' }
})

const expectedSequenceOrder = new Array(N).fill(0).map((_, i) => i + 1)

await Promise.all(
many.map((content) => {
return p(db.create)({ feedFormat: 'classic', content })
})
)
.then((msgs) => {
t.pass('bulk publishes messages')
t.deepEqual(
msgs.map((m) => m.value.sequence),
expectedSequenceOrder,
'messages created in correct order'
)
})
.catch((err) => t.error(err, 'bulk publishes messages'))

const sequencesFromDb = await pull(
db.query(where(type('counter')), toPullStream()),
pull.map((m) => m.value.sequence),
pull.collectAsPromise()
)

t.deepEqual(
sequencesFromDb,
expectedSequenceOrder,
'messages come out of the DB in the right order'
)
t.end()

// TEMP
sbot.close(true, () => t.end())
})

test('create() classic box', (t) => {
db.create(
{
Expand Down

0 comments on commit 5cd23e2

Please sign in to comment.