From 7562c13089fc6584037e91efeb09e162fec4881e Mon Sep 17 00:00:00 2001 From: Christophe Diederichs <45171645+chm-diederichs@users.noreply.github.com> Date: Mon, 19 Feb 2024 10:41:20 +0000 Subject: [PATCH] Teardown test bases that use tmpDir (#48) * teardown bases that use tmpDir * teardown order matters * reenable windows ci * teardown corestore as well * fix suspend tests --- .github/workflows/ci.yaml | 2 +- package.json | 2 +- test/fast-forward.js | 46 ++++++++ test/suspend.js | 233 ++++++++++++++++++++++---------------- 4 files changed, 183 insertions(+), 100 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 647079bb..d9442bd2 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -18,7 +18,7 @@ jobs: strategy: matrix: node-version: [lts/*] - os: [ubuntu-latest, macos-latest] + os: [ubuntu-latest, macos-latest, windows-latest] timeout-minutes: 30 steps: - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 https://github.com/actions/checkout/releases/tag/v4.1.1 diff --git a/package.json b/package.json index e9cb893b..a6797848 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,7 @@ "random-access-memory": "^6.2.0", "same-data": "^1.0.0", "standard": "^17.0.0", - "test-tmp": "^1.0.0" + "test-tmp": "^1.2.0" }, "standard": { "ignore": [ diff --git a/test/fast-forward.js b/test/fast-forward.js index d7101643..5bd928f1 100644 --- a/test/fast-forward.js +++ b/test/fast-forward.js @@ -47,6 +47,13 @@ test('fast-forward - simple', async t => { await b.ready() + t.teardown(async () => { + await a.close() + await b.close() + await store.close() + await store2.close() + }) + for (let i = 0; i < 1000; i++) { await a.append('a' + i) } @@ -72,6 +79,12 @@ test('fast-forward - migrate', async t => { storage: () => tmpDir(t) }) + t.teardown(async () => { + await a.close() + await b.close() + await c.close() + }) + for (let i = 0; i < 2000; i++) { await a.append('a' + i) } @@ -103,6 +116,12 @@ test('fast-forward - fast forward after migrate', async t => { storage: () => tmpDir(t) }) + t.teardown(async () => { + await a.close() + await b.close() + await c.close() + }) + for (let i = 0; i < 2000; i++) { await a.append('a' + i) } @@ -156,6 +175,13 @@ test('fast-forward - multiple writers added', async t => { storage: () => tmpDir(t) }) + t.teardown(async () => { + await a.close() + await b.close() + await c.close() + await d.close() + }) + await addWriterAndSync(a, b) await addWriterAndSync(a, c) @@ -208,6 +234,13 @@ test('fast-forward - multiple queues', async t => { storage: () => tmpDir(t) }) + t.teardown(async () => { + await a.close() + await b.close() + await c.close() + await d.close() + }, { order: 1 }) + // this value should be long enough that 2 fast-forwards are // queued (ie. we don't just replicate the last state), but short // enough that the second is queued before the first has completed @@ -348,6 +381,13 @@ test('fast-forward - open with no remote io', async t => { ackThreshold: 0 }) + t.teardown(async () => { + await a.close() + await b2.close() + await store.close() + await store2.close() + }) + await b2.ready() await t.execution(b2.ready()) @@ -381,6 +421,12 @@ test('fast-forward - force reset then ff', async t => { storage: () => tmpDir(t) }) + t.teardown(async () => { + await a.close() + await b.close() + await c.close() + }) + await addWriterAndSync(a, b) await addWriterAndSync(a, c) await confirm([a, b, c]) diff --git a/test/suspend.js b/test/suspend.js index 17bc5214..d07f6443 100644 --- a/test/suspend.js +++ b/test/suspend.js @@ -96,6 +96,12 @@ test('suspend - pass exisiting fs store', async t => { const base3 = new Autobase(session3, base1.local.key, { apply, valueEncoding: 'json', ackInterval: 0, ackThreshold: 0, fastForward: false }) await base3.ready() + t.teardown(async () => { + await base1.close() + await base3.close() + await store.close() + }) + t.is(base3.activeWriters.size, 2) await base3.append('final') @@ -144,15 +150,18 @@ test('suspend - 2 exisiting fs stores', async t => { const base3 = new Autobase(session3, base1.local.key, { apply, valueEncoding: 'json', ackInterval: 0, ackThreshold: 0, fastForward: false }) await base3.ready() + t.teardown(async () => { + await base1.close() + await base3.close() + await store.close() + await store2.close() + }) + t.is(base3.activeWriters.size, 2) await base3.append('final') await t.execution(replicateAndSync([base3, base1])) - - await base1.close() - await base2.close() - await base3.close() }) test('suspend - reopen after index', async t => { @@ -198,7 +207,7 @@ test('suspend - reopen after index', async t => { await b.close() const session2 = store.session() - const c = new Autobase(session2, a.local.key, { + const b2 = new Autobase(session2, a.local.key, { apply, valueEncoding: 'json', open: store => store.get('view', { @@ -209,28 +218,30 @@ test('suspend - reopen after index', async t => { fastForward: false }) - await c.ready() - await c.update() + t.teardown(async () => { + await a.close() + await b2.close() + await store.close() + }) - t.is(c.view.length, order.length) + await b2.ready() + await b2.update() - for (let i = 0; i < c.view.length; i++) { - t.alike(await c.view.get(i), order[i]) + t.is(b2.view.length, order.length) + + for (let i = 0; i < b2.view.length; i++) { + t.alike(await b2.view.get(i), order[i]) } - t.is(c.activeWriters.size, 2) + t.is(b2.activeWriters.size, 2) - await c.append('final') + await b2.append('final') - await t.execution(replicateAndSync([a, c])) + await t.execution(replicateAndSync([a, b2])) t.is(b.view.indexedLength, 1) - t.is(c.view.indexedLength, 1) - t.is(c.view.length, b.view.length + 2) - - await a.close() - await b.close() - await c.close() + t.is(b2.view.indexedLength, 1) + t.is(b2.view.length, b.view.length + 2) }) test('suspend - reopen with sync in middle', async t => { @@ -313,6 +324,12 @@ test('suspend - reopen with sync in middle', async t => { fastForward: false }) + t.teardown(async () => { + await a.close() + await b2.close() + await store.close() + }) + await b2.ready() await b2.update() @@ -326,10 +343,6 @@ test('suspend - reopen with sync in middle', async t => { t.is(b.view.indexedLength, 1) t.is(b2.view.indexedLength, 1) t.is(b2.view.length, b.view.length + 2) - - await a.close() - await b.close() - await b2.close() }) test('suspend - reopen with indexing in middle', async t => { @@ -390,6 +403,12 @@ test('suspend - reopen with indexing in middle', async t => { fastForward: false }) + t.teardown(async () => { + await a.close() + await c2.close() + await store.close() + }) + await c2.ready() await c2.update() @@ -409,10 +428,6 @@ test('suspend - reopen with indexing in middle', async t => { t.is(b.view.indexedLength, 3) t.is(c2.view.indexedLength, 3) t.is(c2.view.length, 5) - - await a.close() - await b.close() - await c2.close() }) test.skip('suspend - reopen with indexing + sync in middle', async t => { @@ -507,6 +522,12 @@ test.skip('suspend - reopen with indexing + sync in middle', async t => { fastForward: false }) + t.teardown(async () => { + await a.close() + await c2.close() + await store.close() + }) + await c2.ready() t.is(c2.view.length, order.length) @@ -526,10 +547,6 @@ test.skip('suspend - reopen with indexing + sync in middle', async t => { t.is(b.view.indexedLength, 3) t.is(c2.view.indexedLength, 3) t.is(c2.view.length, 5) - - await a.close() - await b.close() - await c2.close() }) test('suspend - non-indexed writer', async t => { @@ -578,7 +595,7 @@ test('suspend - non-indexed writer', async t => { const session2 = store.session() await session2.ready() - const c = new Autobase(session2, a.local.key, { + const b2 = new Autobase(session2, a.local.key, { apply: applyWriter, valueEncoding: 'json', open, @@ -587,15 +604,16 @@ test('suspend - non-indexed writer', async t => { fastForward: false }) - c.debug = true - - await c.ready() + t.teardown(async () => { + await a.close() + await b2.close() + await store.close() + }) - t.is(c.view.indexedLength, a.view.indexedLength) - t.is(c.view.length, a.view.length) + await b2.ready() - await a.close() - await c.close() + t.is(b2.view.indexedLength, a.view.indexedLength) + t.is(b2.view.length, a.view.length) async function applyWriter (batch, view, base) { for (const node of batch) { @@ -662,6 +680,12 @@ test('suspend - open new index after reopen', async t => { fastForward: false }) + t.teardown(async () => { + await a.close() + await b2.close() + await store.close() + }) + await b2.ready() for (let i = 0; i < b2.view.first.length; i++) { @@ -706,9 +730,6 @@ test('suspend - open new index after reopen', async t => { t.alike(acp1, await a.view.first._source._checkpoint()) // t.alike(acp2, await a.view.second._source._checkpoint()) - - await a.close() - await b2.close() }) test('suspend - reopen multiple indexes', async t => { @@ -758,7 +779,7 @@ test('suspend - reopen multiple indexes', async t => { await b.close() const session2 = store.session() - const c = new Autobase(session2, a.local.key, { + const b2 = new Autobase(session2, a.local.key, { valueEncoding: 'json', apply: applyMultiple, open: openMultiple, @@ -767,55 +788,57 @@ test('suspend - reopen multiple indexes', async t => { fastForward: false }) - await c.ready() - await c.update() + t.teardown(async () => { + await a.close() + await b2.close() + await store.close() + }) + + await b2.ready() + await b2.update() - for (let i = 0; i < c.view.first.length; i++) { - t.alike(await c.view.first.get(i), order[i]) + for (let i = 0; i < b2.view.first.length; i++) { + t.alike(await b2.view.first.get(i), order[i]) } - for (let i = 0; i < c.view.second.length; i++) { - t.alike(await c.view.second.get(i), order[i + c.view.first.length]) + for (let i = 0; i < b2.view.second.length; i++) { + t.alike(await b2.view.second.get(i), order[i + b2.view.first.length]) } - t.is(c.activeWriters.size, 2) + t.is(b2.activeWriters.size, 2) - await c.append({ index: 1, data: 'final' }) + await b2.append({ index: 1, data: 'final' }) - t.is(c.view.first.length + c.view.second.length, order.length + 1) + t.is(b2.view.first.length + b2.view.second.length, order.length + 1) - await t.execution(replicateAndSync([a, c])) + await t.execution(replicateAndSync([a, b2])) t.is(b.view.first.indexedLength, 1) - t.is(c.view.first.indexedLength, 1) - t.is(c.view.first.length, b.view.first.length + 2) + t.is(b2.view.first.indexedLength, 1) + t.is(b2.view.first.length, b.view.first.length + 2) - await t.execution(confirm([a, c])) + await t.execution(confirm([a, b2])) const an = await a.local.get(a.local.length - 1) - const cn = await c.local.get(c.local.length - 1) + const b2n = await b2.local.get(b2.local.length - 1) t.is(an.checkpoint.length, 3) - t.is(cn.checkpoint.length, 3) + t.is(b2n.checkpoint.length, 3) const acp1 = await a.localWriter.getCheckpoint(1) const acp2 = await a.localWriter.getCheckpoint(2) - const ccp1 = await c.localWriter.getCheckpoint(1) - const ccp2 = await c.localWriter.getCheckpoint(2) + const b2cp1 = await b2.localWriter.getCheckpoint(1) + const b2cp2 = await b2.localWriter.getCheckpoint(2) t.alike(acp1.length, 4) t.alike(acp2.length, 2) - t.alike(acp1.length, ccp1.length) - t.alike(acp2.length, ccp2.length) + t.alike(acp1.length, b2cp1.length) + t.alike(acp2.length, b2cp2.length) t.alike(acp1, await a.view.first._source._checkpoint()) t.alike(acp2, await a.view.second._source._checkpoint()) - - await a.close() - await b.close() - await c.close() }) test('restart non writer', async t => { @@ -888,7 +911,7 @@ test('suspend - non-indexed writer catches up', async t => { const session2 = store.session() await session2.ready() - const c = new Autobase(session2, a.local.key, { + const b2 = new Autobase(session2, a.local.key, { applyWriter, valueEncoding: 'json', open, @@ -897,12 +920,15 @@ test('suspend - non-indexed writer catches up', async t => { fastForward: false }) - await c.ready() + t.teardown(async () => { + await a.close() + await b2.close() + await store.close() + }) - t.pass('did not fail on open') + await b2.ready() - await a.close() - await c.close() + t.pass('did not fail on open') async function applyWriter (batch, view, base) { for (const node of batch) { @@ -970,6 +996,12 @@ test.skip('suspend - append but not indexed then reopen', async t => { fastForward: false }) + t.teardown(async () => { + await a.close() + await c2.close() + await store.close() + }) + await c2.ready() // c hasn't seen any appends to first @@ -1012,10 +1044,6 @@ test.skip('suspend - append but not indexed then reopen', async t => { t.alike(acp1, await a.view.first._source._checkpoint()) // t.alike(acp2, await a.view.second._source._checkpoint()) - - await a.close() - await b.close() - await c2.close() }) test('suspend - migrations', async t => { @@ -1070,7 +1098,7 @@ test('suspend - migrations', async t => { await b.close() const session2 = store.session() - const c = new Autobase(session2, a.local.key, { + const b2 = new Autobase(session2, a.local.key, { apply, valueEncoding: 'json', open: store => store.get('view', { @@ -1081,32 +1109,34 @@ test('suspend - migrations', async t => { fastForward: false }) - await c.ready() + t.teardown(async () => { + await a.close() + await b2.close() + await store.close() + }) + + await b2.ready() - t.is(c.view.indexedLength, 3) - t.is(c.view.signedLength, 3) - t.is(c.view.getBackingCore().indexedLength, 3) + t.is(b2.view.indexedLength, 3) + t.is(b2.view.signedLength, 3) + t.is(b2.view.getBackingCore().indexedLength, 3) - await c.update() + await b2.update() - t.is(c.view.length, order.length) - for (let i = 0; i < c.view.length; i++) { - t.alike(await c.view.get(i), order[i]) + t.is(b2.view.length, order.length) + for (let i = 0; i < b2.view.length; i++) { + t.alike(await b2.view.get(i), order[i]) } - t.is(c.activeWriters.size, 2) + t.is(b2.activeWriters.size, 2) - await c.append('final') + await b2.append('final') - await t.execution(replicateAndSync([a, c])) + await t.execution(replicateAndSync([a, b2])) t.is(b.view.indexedLength, 3) - t.is(c.view.indexedLength, 3) - t.is(c.view.length, b.view.length + 1) - - await a.close() - await b.close() - await c.close() + t.is(b2.view.indexedLength, 3) + t.is(b2.view.length, b.view.length + 1) }) test('suspend - append waits for drain after boot', async t => { @@ -1144,13 +1174,17 @@ test('suspend - append waits for drain after boot', async t => { fastForward: false }) + t.teardown(async () => { + await a.close() + await b2.close() + await store.close() + }) + await b2.append({ last: true }) const { node } = await b2.localWriter.core.get(b2.localWriter.core.length - 1) t.is(node.heads.length, 1) t.is(node.heads[0].length, 101) // links the last node - - await store.close() }) test('suspend - incomplete migrate', async t => { @@ -1210,6 +1244,12 @@ test('suspend - incomplete migrate', async t => { fastForward: false }) + t.teardown(async () => { + await a.close() + await b2.close() + await store.close() + }) + await b2.ready() t.is(a.view.indexedLength, 2) @@ -1225,9 +1265,6 @@ test('suspend - incomplete migrate', async t => { t.is(b2.activeWriters.size, 2) await t.execution(replicateAndSync([a, b2])) - - await a.close() - await b2.close() }) function open (store) {