Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
ronag committed Jul 12, 2021
1 parent e8a4ee2 commit 346cda7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
17 changes: 11 additions & 6 deletions test/parallel/test-stream-writable-destroy.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,33 +351,35 @@ const assert = require('assert');
const write = new Writable({
write(chunk, enc, cb) { process.nextTick(cb); }
});
const _err = new Error('asd');
write.once('error', common.mustCall((err) => {
assert.strictEqual(err.message, 'asd');
}));
write.end('asd', common.mustCall((err) => {
assert.strictEqual(err.code, 'ERR_STREAM_DESTROYED');
assert.strictEqual(err, _err);
}));
write.destroy(new Error('asd'));
write.destroy(_err);
}

{
// Call buffered write callback with error

const _err = new Error('asd');
const write = new Writable({
write(chunk, enc, cb) {
process.nextTick(cb, new Error('asd'));
process.nextTick(cb, _err);
},
autoDestroy: false
});
write.cork();
write.write('asd', common.mustCall((err) => {
assert.strictEqual(err.message, 'asd');
assert.strictEqual(err, _err);
}));
write.write('asd', common.mustCall((err) => {
assert.strictEqual(err.code, 'ERR_STREAM_DESTROYED');
assert.strictEqual(err, _err);
}));
write.on('error', common.mustCall((err) => {
assert.strictEqual(err.message, 'asd');
assert.strictEqual(err, _err);
}));
write.uncork();
}
Expand Down Expand Up @@ -482,5 +484,8 @@ const assert = require('assert');
s.end(common.mustCall((err) => {
assert.strictEqual(err, _err);
}));
s.on('error', (err) => {
assert.strictEqual(err, _err);
});
s.destroy(_err);
}
19 changes: 7 additions & 12 deletions test/parallel/test-stream-writable-end-cb-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,20 @@ const stream = require('stream');
// Invoke end callback on failure.
const writable = new stream.Writable();

const _err = new Error('kaboom');
writable._write = (chunk, encoding, cb) => {
process.nextTick(cb, new Error('kaboom'));
process.nextTick(cb, _err);
};

writable.on('error', common.mustCall((err) => {
assert.strictEqual(err.message, 'kaboom');
assert.strictEqual(err, _err);
}));
writable.write('asd');
writable.end(common.mustCall((err) => {
assert.strictEqual(err.code, 'ERR_STREAM_DESTROYED');
assert.strictEqual(err, _err);
}));
writable.end(common.mustCall((err) => {
assert.strictEqual(err.code, 'ERR_STREAM_DESTROYED');
assert.strictEqual(err, _err);
}));
}

Expand Down Expand Up @@ -57,18 +58,12 @@ const stream = require('stream');
}
});
w.end('testing ended state', common.mustCall((err) => {
// This errors since .destroy(err), which is invoked by errors
// in same tick below, will error all pending callbacks.
// Does this make sense? Not sure.
assert.strictEqual(err.code, 'ERR_STREAM_DESTROYED');
assert.strictEqual(err.code, 'ERR_STREAM_WRITE_AFTER_END');
}));
assert.strictEqual(w.destroyed, false);
assert.strictEqual(w.writableEnded, true);
w.end(common.mustCall((err) => {
// This errors since .destroy(err), which is invoked by errors
// in same tick below, will error all pending callbacks.
// Does this make sense? Not sure.
assert.strictEqual(err.code, 'ERR_STREAM_DESTROYED');
assert.strictEqual(err.code, 'ERR_STREAM_WRITE_AFTER_END');
}));
assert.strictEqual(w.destroyed, false);
assert.strictEqual(w.writableEnded, true);
Expand Down

0 comments on commit 346cda7

Please sign in to comment.