Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add test for live pull-stream #76

Merged
merged 2 commits into from Jun 28, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 0 additions & 5 deletions errors.js
Expand Up @@ -42,10 +42,6 @@ function appendLargerThanBlockErr() {
return new Error('Data to be appended is larger than block size')
}

function streamClosedErr() {
return new Error('async-append-only-log stream is closed')
}

function appendTransactionWantsArrayErr() {
return new Error('appendTransaction expects first argument to be an array')
}
Expand All @@ -66,7 +62,6 @@ module.exports = {
deletedRecordErr,
delDuringCompactErr,
appendLargerThanBlockErr,
streamClosedErr,
appendTransactionWantsArrayErr,
unexpectedTruncationErr,
}
3 changes: 1 addition & 2 deletions index.js
Expand Up @@ -18,7 +18,6 @@ const {
outOfBoundsOffsetErr,
delDuringCompactErr,
appendLargerThanBlockErr,
streamClosedErr,
appendTransactionWantsArrayErr,
unexpectedTruncationErr,
} = require('./errors')
Expand Down Expand Up @@ -514,7 +513,7 @@ module.exports = function AsyncAppendOnlyLog(filename, opts) {
function close(cb) {
onDrain(function closeAfterHavingDrained() {
onDeletesFlushed(function closeAfterDeletesFlushed() {
for (const stream of self.streams) stream.abort(streamClosedErr())
for (const stream of self.streams) stream.abort(true)
self.streams = []
raf.close(cb)
})
Expand Down
52 changes: 52 additions & 0 deletions test/stream-abort.js
@@ -0,0 +1,52 @@
// SPDX-FileCopyrightText: 2022 Andre 'Staltz' Medeiros <contact@staltz.com>
//
// SPDX-License-Identifier: CC0-1.0

const tape = require('tape')
const fs = require('fs')
const toPull = require('push-stream-to-pull-stream/source')
const pull = require('pull-stream')
const Log = require('../')

const filename = '/tmp/aaol-abort-live-pull-stream.log'

try {
fs.unlinkSync(filename)
} catch (_) {}
const log = Log(filename, { blockSize: 64 * 1024 })

const msg1 = Buffer.alloc(10).fill(0x10)
const msg2 = Buffer.alloc(20).fill(0x20)
const msg3 = Buffer.alloc(30).fill(0x30)

tape('abort live push-stream-to-pull-stream should not end with err', (t) => {
t.plan(8)
log.append(msg1, (err) => {
t.error(err, 'no err to append msg1')
log.append(msg2, (err) => {
t.error(err, 'no err to append msg2')
const expected = [msg1, msg2, msg3]
const logPushStream = log.stream({ live: true, offsets: false })
const logPullStream = toPull(logPushStream)
pull(
logPullStream,
pull.drain(
(buf) => {
t.deepEqual(buf, expected.shift())
if (expected.length === 0) {
log.close(() => {
t.pass('closed AAOL')
})
}
},
(err) => {
t.error(err, 'no err when pull.draining')
}
)
)
})
})
log.append(msg3, (err) => {
t.error(err, 'no err to append msg3')
})
})