Skip to content

Commit

Permalink
Do not assert corestore size
Browse files Browse the repository at this point in the history
  • Loading branch information
HDegroote committed Feb 24, 2025
1 parent 34f73de commit 529d148
Showing 1 changed file with 1 addition and 20 deletions.
21 changes: 1 addition & 20 deletions test/clear.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
const path = require('path')
const test = require('brittle')
const tmp = require('test-tmp')
const b4a = require('b4a')
const createTempDir = require('test-tmp')
const CoreStorage = require('hypercore-storage')
const { create, createStorage, replicate, eventFlush } = require('./helpers')
const { readdir, stat } = require('fs/promises')

const Hypercore = require('../')

Expand Down Expand Up @@ -132,7 +130,7 @@ test('clear - no side effect from clearing unknown nodes', async function (t) {
t.pass('did not crash')
})

test.solo('clear - large cores', async function (t) {
test('clear - large cores', async function (t) {
t.timeout(100000)
const dir = await createTempDir(t)
console.log(dir)
Expand All @@ -148,7 +146,6 @@ test.solo('clear - large cores', async function (t) {
await new Promise(resolve => setTimeout(resolve, 1000))

t.is(a.contiguousLength, 300_000, 'sanity checck')
const preClearDirSize = await getDirSize(dir)

await a.clear(100, 1000)
await a.clear(2 ** 16 - 10, 2 ** 16 + 10) // 2 ** 16 is when the bitfield first changes pages, so interesting are to test
Expand All @@ -168,20 +165,4 @@ test.solo('clear - large cores', async function (t) {
t.is(await a.get(290000, { wait: false }), null)
t.is(await a.get(299997, { wait: false }), null)
t.is((await a.get(299998)).toString(), 'Block-299998')

const partiallyClearedDirSize = await getDirSize(dir)
t.is(partiallyClearedDirSize < preClearDirSize, true, 'Storage reduced in size post clearing')

console.log('a length', a.lenght)
await a.clear(0, a.length)
await new Promise(resolve => setTimeout(resolve, 1000))
const fullyClearedDirSize = await getDirSize(dir)
console.log({ preClearDirSize, partiallyClearedDirSize, fullyClearedDirSize })
})

async function getDirSize (directory) {
const files = await readdir(directory)
const stats = files.map(file => stat(path.join(directory, file)))
const res = (await Promise.all(stats)).reduce((accumulator, { size }) => accumulator + size, 0)
return res
}

0 comments on commit 529d148

Please sign in to comment.