Skip to content

Commit

Permalink
Test contiguousLength across restarts (#654)
Browse files Browse the repository at this point in the history
  • Loading branch information
HDegroote authored Feb 27, 2025
1 parent 47e5f8b commit 84c212d
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions test/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,9 @@ test('truncate has correct storage state in memory and persisted', async functio
await core.append(['a', 'b', 'c', 'd', 'e'])
await core.truncate(2)
t.alike(getBitfields(core, 0, 5), [true, true, false, false, false])
t.is(core.contiguousLength, 2)
t.is(core.core.header.hints.contiguousLength, 2)
t.is(await getContiguousLengthInStorage(core), 2)
await core.close()
}

Expand All @@ -612,6 +615,9 @@ test('truncate has correct storage state in memory and persisted', async functio
const core = new Hypercore(storage)
await core.ready()
t.alike(getBitfields(core, 0, 5), [true, true, false, false, false])
t.is(core.contiguousLength, 2)
t.is(core.core.header.hints.contiguousLength, 2)
t.is(await getContiguousLengthInStorage(core), 2)
await core.close()
}
})
Expand All @@ -624,6 +630,9 @@ test('clear has correct storage state in memory and persisted', async function (
await core.append(['a', 'b', 'c', 'd', 'e'])
await core.clear(2)
t.alike(getBitfields(core, 0, 5), [true, true, false, true, true])
t.is(core.contiguousLength, 2)
t.is(core.core.header.hints.contiguousLength, 2)
t.is(await getContiguousLengthInStorage(core), 2)
await core.close()
}

Expand All @@ -632,6 +641,9 @@ test('clear has correct storage state in memory and persisted', async function (
const core = new Hypercore(storage)
await core.ready()
t.alike(getBitfields(core, 0, 5), [true, true, false, true, true])
t.is(core.contiguousLength, 2)
t.is(core.core.header.hints.contiguousLength, 2)
t.is(await getContiguousLengthInStorage(core), 2)
await core.close()
}
})
Expand All @@ -646,3 +658,9 @@ function getBitfields (hypercore, start = 0, end = null) {

return res
}

async function getContiguousLengthInStorage (hypercore) {
const storageRx = hypercore.core.storage.read()
const [res] = await Promise.all([storageRx.getHints(), storageRx.tryFlush()])
return res?.contiguousLength || null
}

0 comments on commit 84c212d

Please sign in to comment.