This commit is contained in:
Raven Scott
2026-05-20 22:28:59 -04:00
parent 341542f41b
commit e4400872c0
82 changed files with 2533 additions and 775 deletions
@@ -4,23 +4,34 @@ const { HyperP2PDocumentLineLock, PROTOCOL } = require('../index.js')
test('exports', (t) => {
t.ok(HyperP2PDocumentLineLock)
t.ok(PROTOCOL)
t.is(PROTOCOL, 'document-line-lock/v1')
})
test('basic operation', async (t) => {
test('acquire and release', async (t) => {
const m = new HyperP2PDocumentLineLock()
m.put('k', 1); t.is(m.get('k'), 1)
const r = m.acquire('doc', 5)
t.ok(r.ok)
t.ok(m.isLocked('doc', 5))
t.ok(m.release('doc', 5))
await m.close()
})
test('conflict', async (t) => {
const m = new HyperP2PDocumentLineLock()
m._onGossip({ type: 'line-lock', lock: { docId: 'd', line: 1, holder: 'other', at: 1 } })
const r = m.acquire('d', 1)
t.is(r.ok, false)
await m.close()
})
test('validation', async (t) => {
const m = new HyperP2PDocumentLineLock()
try { m.put(null, 1) } catch (e) { t.ok(e) }
try { m.acquire('', 0) } catch (e) { t.ok(e) }
await m.close()
})
test('getStats', async (t) => {
const m = new HyperP2PDocumentLineLock()
t.ok(m.getStats().protocol)
t.is(m.getStats().protocol, 'document-line-lock/v1')
await m.close()
})