Skip to content

Commit c7b1841

Browse files
LiviaMedeirosnodejs-github-bot
authored andcommitted
stream: test explicit resource management implicitly
PR-URL: #58296 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent e2cf695 commit c7b1841

File tree

4 files changed

+55
-0
lines changed

4 files changed

+55
-0
lines changed

test/parallel/test-stream-duplex-destroy.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,3 +284,17 @@ const assert = require('assert');
284284
duplex.on('close', common.mustCall());
285285
duplex[Symbol.asyncDispose]().then(common.mustCall());
286286
}
287+
288+
(async () => {
289+
// Check Symbol.asyncDispose implicitly
290+
await using duplex = new Duplex({
291+
write(chunk, enc, cb) { cb(); },
292+
read() {},
293+
});
294+
duplex.on('error', common.mustCall(function(e) {
295+
assert.strictEqual(e.name, 'AbortError');
296+
assert.strictEqual(this.destroyed, true);
297+
assert.strictEqual(this.errored.name, 'AbortError');
298+
}));
299+
duplex.on('close', common.mustCall());
300+
})().then(common.mustCall());

test/parallel/test-stream-readable-dispose.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,18 @@ const assert = require('assert');
2121
assert.strictEqual(read.destroyed, true);
2222
}));
2323
}
24+
25+
(async () => {
26+
await using read = new Readable({
27+
read() {}
28+
});
29+
read.resume();
30+
31+
read.on('end', common.mustNotCall('no end event'));
32+
read.on('close', common.mustCall());
33+
read.on('error', common.mustCall(function(err) {
34+
assert.strictEqual(err.name, 'AbortError');
35+
assert.strictEqual(this.errored.name, 'AbortError');
36+
assert.strictEqual(this.destroyed, true);
37+
}));
38+
})().then(common.mustCall());

test/parallel/test-stream-transform-destroy.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,3 +152,15 @@ const assert = require('assert');
152152
transform.on('close', common.mustCall());
153153
transform[Symbol.asyncDispose]().then(common.mustCall());
154154
}
155+
156+
(async () => {
157+
await using transform = new Transform({
158+
transform(chunk, enc, cb) {}
159+
});
160+
transform.on('error', common.mustCall(function(err) {
161+
assert.strictEqual(err.name, 'AbortError');
162+
assert.strictEqual(this.destroyed, true);
163+
assert.strictEqual(this.errored.name, 'AbortError');
164+
}));
165+
transform.on('close', common.mustCall());
166+
})().then(common.mustCall());

test/parallel/test-stream-writable-destroy.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,3 +499,17 @@ const assert = require('assert');
499499
}));
500500
write[Symbol.asyncDispose]().then(common.mustCall());
501501
}
502+
503+
(async () => {
504+
await using write = new Writable({
505+
write(chunk, enc, cb) { cb(); }
506+
});
507+
508+
write.on('error', common.mustCall(function(e) {
509+
assert.strictEqual(e.name, 'AbortError');
510+
assert.strictEqual(this.destroyed, true);
511+
assert.strictEqual(this.errored.name, 'AbortError');
512+
}));
513+
write.on('close', common.mustCall());
514+
write.on('finish', common.mustNotCall('no finish event'));
515+
})().then(common.mustCall());

0 commit comments

Comments
 (0)