Skip to content
Merged
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
50 changes: 26 additions & 24 deletions test/02log.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ const test = require('tape')
const { FsLog } = require('../src/index.js')
const { Encoder, XxHashEncoder } = require('../src/index.js')

const DIR = process.env.TEST_DIR ?? '/tmp/'

const toBuf = (obj) => {
if (obj === null) { return null }
obj = JSON.stringify(obj)
Expand All @@ -18,7 +20,7 @@ async function testAppendOpenCloseNew(t, encoder) {
t.teardown(() => log.close())

const opts = { encoder }
let log = new FsLog('/tmp/', 'test', opts)
let log = new FsLog(DIR, 'test', opts)

await log.del()
await log.open()
Expand Down Expand Up @@ -58,7 +60,7 @@ async function testAppendOpenCloseNew(t, encoder) {
await log.close()

// new
log = new FsLog('/tmp/', 'test', opts)
log = new FsLog(DIR, 'test', opts)
await log.open()
t.equal(log.seq, 3n, 'seq = 3 again')
t.deepEqual(toObj(log.head), data, 'head = data again')
Expand All @@ -79,7 +81,7 @@ async function testAppendOneCloseOpen(t, encoder) {
t.teardown(() => log.close())

const opts = { encoder }
const log = new FsLog('/tmp/', 'test', opts)
const log = new FsLog(DIR, 'test', opts)

await log.del()
await log.open()
Expand Down Expand Up @@ -118,7 +120,7 @@ async function testRollbackFirst(t, encoder) {
}

const opts = { encoder, rollbackCb }
const log = new FsLog('/tmp/', 'test', opts)
const log = new FsLog(DIR, 'test', opts)

await log.del()
await log.open()
Expand Down Expand Up @@ -151,7 +153,7 @@ async function testRollbackSecond(t, encoder) {
}

const opts = { encoder, rollbackCb }
const log = new FsLog('/tmp/', 'test', opts)
const log = new FsLog(DIR, 'test', opts)

await log.del()
await log.open()
Expand Down Expand Up @@ -189,7 +191,7 @@ async function testRollbackThird(t, encoder) {
}

const opts = { encoder, rollbackCb }
const log = new FsLog('/tmp/', 'test', opts)
const log = new FsLog(DIR, 'test', opts)

await log.del()
await log.open()
Expand Down Expand Up @@ -226,7 +228,7 @@ async function testTrim(t, encoder) {
t.teardown(() => log.close())

const opts = { encoder }
const log = new FsLog('/tmp/', 'test', opts)
const log = new FsLog(DIR, 'test', opts)

await log.del()
await log.open()
Expand Down Expand Up @@ -276,7 +278,7 @@ async function testTrim2(t, encoder) {
t.teardown(() => log.close())

const opts = { encoder }
const log = new FsLog('/tmp/', 'test', opts)
const log = new FsLog(DIR, 'test', opts)

await log.del()
await log.open()
Expand Down Expand Up @@ -304,7 +306,7 @@ async function testTrim3(t, encoder) {
}

const opts = { encoder, rollForwardCb }
const log = new FsLog('/tmp/', 'test', opts)
const log = new FsLog(DIR, 'test', opts)

await log.del()
await log.open()
Expand All @@ -331,7 +333,7 @@ async function testBatch(t, encoder) {
t.teardown(() => log.close())

const opts = { encoder }
const log = new FsLog('/tmp/', 'test', opts)
const log = new FsLog(DIR, 'test', opts)

await log.del()
await log.open()
Expand Down Expand Up @@ -373,7 +375,7 @@ async function testBatchOpenCloseNew(t, encoder) {
t.teardown(() => log.close())

const opts = { encoder }
let log = new FsLog('/tmp/', 'test', opts)
let log = new FsLog(DIR, 'test', opts)

await log.del()
await log.open()
Expand Down Expand Up @@ -414,7 +416,7 @@ async function testBatchOpenCloseNew(t, encoder) {
t.deepEqual(toObj(log.head), data[1], 'head = data')
await log.close()

log = new FsLog('/tmp/', 'test', opts)
log = new FsLog(DIR, 'test', opts)
await log.open()
t.equal(log.seq, 5n, 'seq = 5')
t.deepEqual(toObj(log.head), data[1], 'head = data')
Expand All @@ -433,7 +435,7 @@ async function testBatchRollback(t, encoder) {
}

const opts = { encoder, rollbackCb }
const log = new FsLog('/tmp/', 'test', opts)
const log = new FsLog(DIR, 'test', opts)

await log.del()
await log.open()
Expand Down Expand Up @@ -466,7 +468,7 @@ async function testBatchRollback2(t, encoder) {
}

const opts = { encoder, rollbackCb }
const log = new FsLog('/tmp/', 'test', opts)
const log = new FsLog(DIR, 'test', opts)

await log.del()
await log.open()
Expand Down Expand Up @@ -502,7 +504,7 @@ async function testBatchRollback3(t, encoder) {
}

const opts = { encoder, rollbackCb }
const log = new FsLog('/tmp/', 'test', opts)
const log = new FsLog(DIR, 'test', opts)

await log.del()
await log.open()
Expand Down Expand Up @@ -540,7 +542,7 @@ async function testBatchTrim(t, encoder) {
t.teardown(() => log.close())

const opts = { encoder }
const log = new FsLog('/tmp/', 'test', opts)
const log = new FsLog(DIR, 'test', opts)

await log.del()
await log.open()
Expand All @@ -562,7 +564,7 @@ async function testBatchTrim2(t, encoder) {
t.teardown(() => log.close())

const opts = { encoder }
const log = new FsLog('/tmp/', 'test', opts)
const log = new FsLog(DIR, 'test', opts)

await log.del()
await log.open()
Expand All @@ -589,7 +591,7 @@ async function testBatchTrim3(t, encoder) {
t.teardown(() => log.close())

const opts = { encoder }
const log = new FsLog('/tmp/', 'test', opts)
const log = new FsLog(DIR, 'test', opts)

await log.del()
await log.open()
Expand Down Expand Up @@ -620,7 +622,7 @@ async function testAppendBufEmpty(t, encoder) {
t.teardown(() => log.close())

const opts = { encoder }
let log = new FsLog('/tmp/', 'test', opts)
let log = new FsLog(DIR, 'test', opts)

await log.del()
await log.open()
Expand Down Expand Up @@ -660,7 +662,7 @@ async function testAppendBufEmpty(t, encoder) {
await log.close()

// new
log = new FsLog('/tmp/', 'test', opts)
log = new FsLog(DIR, 'test', opts)
await log.open()
t.equal(log.seq, 3n, 'seq = 3 again')
t.deepEqual(toObj(log.head), data, 'head = data again')
Expand All @@ -681,7 +683,7 @@ async function testAppendBatchBufEmpty(t, encoder) {
t.teardown(() => log.close())

const opts = { encoder }
let log = new FsLog('/tmp/', 'test', opts)
let log = new FsLog(DIR, 'test', opts)

await log.del()
await log.open()
Expand Down Expand Up @@ -722,7 +724,7 @@ async function testAppendBatchBufEmpty(t, encoder) {
t.ok(log.head.equals(data[1]), 'head = data')
await log.close()

log = new FsLog('/tmp/', 'test', opts)
log = new FsLog(DIR, 'test', opts)
await log.open()
t.equal(log.seq, 5n, 'seq = 5')
t.ok(log.head.equals(data[1]), 'head = data')
Expand All @@ -736,7 +738,7 @@ async function testDoubleOpen(t, encoder) {
t.plan(1)
t.teardown(() => log.close())
const opts = { encoder }
const log = new FsLog('/tmp/', 'test', opts)
const log = new FsLog(DIR, 'test', opts)
await log.del()
const p1 = log.open()
const p2 = log.open()
Expand All @@ -749,7 +751,7 @@ async function testDoubleClose(t, encoder) {
t.plan(1)
t.teardown(() => log.close())
const opts = { encoder }
const log = new FsLog('/tmp/', 'test', opts)
const log = new FsLog(DIR, 'test', opts)
await log.del()
await log.open()
const p1 = log.close()
Expand Down
18 changes: 10 additions & 8 deletions test/03txn.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ const { FsLog } = require('../src/index.js')
const { TimeoutLog } = require('../src/index.js')
const { Encoder, XxHashEncoder } = require('../src/index.js')

const DIR = process.env.TEST_DIR ?? '/tmp/'

const toBuf = (obj) => {
if (obj === null) { return null }
obj = JSON.stringify(obj)
Expand All @@ -19,7 +21,7 @@ async function testTxnAppend(t, encoder, time=false) {
t.teardown(() => log.close())

const opts = { encoder }
let log = new FsLog('/tmp/', 'test', opts)
let log = new FsLog(DIR, 'test', opts)
log = time ? new TimeoutLog(log, {}) : log

await log.del()
Expand Down Expand Up @@ -65,7 +67,7 @@ async function testTxnAppendBatch(t, encoder, time=false) {
t.teardown(() => log.close())

const opts = { encoder }
let log = new FsLog('/tmp/', 'test', opts)
let log = new FsLog(DIR, 'test', opts)
log = time ? new TimeoutLog(log, {}) : log

await log.del()
Expand Down Expand Up @@ -111,7 +113,7 @@ async function testTxnWithOpenClose(t, encoder, time=false) {
t.teardown(() => log.close())

const opts = { encoder }
let log = new FsLog('/tmp/', 'test', opts)
let log = new FsLog(DIR, 'test', opts)
log = time ? new TimeoutLog(log, {}) : log

await log.del()
Expand Down Expand Up @@ -155,7 +157,7 @@ async function testTxnWithOpenClose(t, encoder, time=false) {
await log.close()

// new
log = new FsLog('/tmp/', 'test', opts)
log = new FsLog(DIR, 'test', opts)
log = time ? new TimeoutLog(log, {}) : log
await log.open()
t.equal(log.seq, 3n, 'seq = 3 again')
Expand Down Expand Up @@ -184,7 +186,7 @@ async function testTxnIsBlocking(t, encoder, time=false) {
t.teardown(() => log.close())

const opts = { encoder }
let log = new FsLog('/tmp/', 'test', opts)
let log = new FsLog(DIR, 'test', opts)
log = time ? new TimeoutLog(log, {}) : log

await log.del()
Expand Down Expand Up @@ -247,7 +249,7 @@ async function testCloseAwaitsTxn(t, encoder, time=false) {
t.teardown(() => log.close())

const opts = { encoder }
let log = new FsLog('/tmp/', 'test', opts)
let log = new FsLog(DIR, 'test', opts)
log = time ? new TimeoutLog(log, {}) : log

await log.del()
Expand Down Expand Up @@ -289,7 +291,7 @@ async function testTxnDoubleCommitDoubleAbort(t, encoder, time=false) {
t.teardown(() => log.close())

const opts = { encoder }
let log = new FsLog('/tmp/', 'test', opts)
let log = new FsLog(DIR, 'test', opts)
log = time ? new TimeoutLog(log, {}) : log

await log.del()
Expand Down Expand Up @@ -344,7 +346,7 @@ async function testTxnTrim(t, encoder, time=false) {
t.teardown(() => log.close())

const opts = { encoder }
let log = new FsLog('/tmp/', 'test', opts)
let log = new FsLog(DIR, 'test', opts)
log = time ? new TimeoutLog(log, {}) : log

await log.del()
Expand Down
Loading