stream: test explicit resource management implicitly

PR-URL: https://github.com/nodejs/node/pull/58296
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
LiviaMedeiros 2025-05-12 22:27:33 +08:00 committed by Node.js GitHub Bot
parent e2cf695021
commit c7b18412a0
4 changed files with 55 additions and 0 deletions

View File

@ -284,3 +284,17 @@ const assert = require('assert');
duplex.on('close', common.mustCall());
duplex[Symbol.asyncDispose]().then(common.mustCall());
}
(async () => {
// Check Symbol.asyncDispose implicitly
await using duplex = new Duplex({
write(chunk, enc, cb) { cb(); },
read() {},
});
duplex.on('error', common.mustCall(function(e) {
assert.strictEqual(e.name, 'AbortError');
assert.strictEqual(this.destroyed, true);
assert.strictEqual(this.errored.name, 'AbortError');
}));
duplex.on('close', common.mustCall());
})().then(common.mustCall());

View File

@ -21,3 +21,18 @@ const assert = require('assert');
assert.strictEqual(read.destroyed, true);
}));
}
(async () => {
await using read = new Readable({
read() {}
});
read.resume();
read.on('end', common.mustNotCall('no end event'));
read.on('close', common.mustCall());
read.on('error', common.mustCall(function(err) {
assert.strictEqual(err.name, 'AbortError');
assert.strictEqual(this.errored.name, 'AbortError');
assert.strictEqual(this.destroyed, true);
}));
})().then(common.mustCall());

View File

@ -152,3 +152,15 @@ const assert = require('assert');
transform.on('close', common.mustCall());
transform[Symbol.asyncDispose]().then(common.mustCall());
}
(async () => {
await using transform = new Transform({
transform(chunk, enc, cb) {}
});
transform.on('error', common.mustCall(function(err) {
assert.strictEqual(err.name, 'AbortError');
assert.strictEqual(this.destroyed, true);
assert.strictEqual(this.errored.name, 'AbortError');
}));
transform.on('close', common.mustCall());
})().then(common.mustCall());

View File

@ -499,3 +499,17 @@ const assert = require('assert');
}));
write[Symbol.asyncDispose]().then(common.mustCall());
}
(async () => {
await using write = new Writable({
write(chunk, enc, cb) { cb(); }
});
write.on('error', common.mustCall(function(e) {
assert.strictEqual(e.name, 'AbortError');
assert.strictEqual(this.destroyed, true);
assert.strictEqual(this.errored.name, 'AbortError');
}));
write.on('close', common.mustCall());
write.on('finish', common.mustNotCall('no finish event'));
})().then(common.mustCall());