mirror of
https://github.com/zebrajr/node.git
synced 2025-12-06 00:20:08 +01:00
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:
parent
e2cf695021
commit
c7b18412a0
|
|
@ -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());
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user