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

added resuse session id test #156

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"ready-resource": "^1.0.0",
"safety-catch": "^1.0.2",
"streamx": "^2.12.4",
"test-tmp": "^1.2.1",
"xache": "^1.2.1"
},
"devDependencies": {
Expand Down
43 changes: 43 additions & 0 deletions test/basic.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const test = require('brittle')
const b4a = require('b4a')
const { create, collect, createCore } = require('./helpers')
const Hypercore = require('hypercore')
const tmp = require('test-tmp')

const Hyperbee = require('..')

Expand Down Expand Up @@ -539,3 +541,44 @@ test('get by seq', async function (t) {
t.alike(await db.getBySeq(1), { key: '/a', value: '1' })
t.alike(await db.getBySeq(2), { key: '/b', value: '2' })
})

test('session id reuse does not stall', async function (t) {
t.plan(1)

const a = new Hypercore(await tmp(t))
await a.ready()

const b = new Hypercore(await tmp(t), a.key)
await b.ready()

const n = 3000

const s1 = a.replicate(true, { keepAlive: false })
const s2 = b.replicate(false, { keepAlive: false })

s1.pipe(s2).pipe(s1)

const beeA = new Hyperbee(a)
const beeB = new Hyperbee(b)

const batch = beeA.batch()

const entries = Array(n).fill().map(e => b4a.from([0])).map((e, i) => {
const buffer = b4a.alloc(2)
buffer.writeUInt16BE(i)
return batch.put(buffer, Buffer.alloc(1))
})

await Promise.all(entries)
await batch.flush()

const requests = Array(n).fill().map(async (e, i) => {
const buffer = b4a.alloc(2)
buffer.writeUInt16BE(i)
return beeB.get(buffer)
})

await Promise.all(requests)

t.pass('All requests completed')
})