Skip to content

Commit 4c98da4

Browse files
committed
stream: test explicit resource management implicitly
1 parent 94ffcdb commit 4c98da4

File tree

4 files changed

+53
-1
lines changed

4 files changed

+53
-1
lines changed

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ const assert = require('assert');
271271
}
272272

273273
{
274-
// Check Symbol.asyncDispose
274+
// Check Symbol.asyncDispose explicitly
275275
const duplex = new Duplex({
276276
write(chunk, enc, cb) { cb(); },
277277
read() {},
@@ -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+
let count = 0;
295+
duplex.on('error', common.mustCall((e) => {
296+
assert.strictEqual(count++, 0); // Ensure not called twice
297+
assert.strictEqual(e.name, 'AbortError');
298+
}));
299+
duplex.on('close', common.mustCall());
300+
})().then(common.mustCall(), common.mustNotCall());

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(), common.mustNotCall());

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,3 +152,13 @@ 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((err) => {
161+
assert.strictEqual(err.name, 'AbortError');
162+
}));
163+
transform.on('close', common.mustCall());
164+
})().then(common.mustCall(), common.mustNotCall());

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,3 +499,16 @@ 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+
}));
512+
write.on('close', common.mustCall());
513+
write.on('finish', common.mustNotCall('no finish event'));
514+
})().then(common.mustCall(), common.mustNotCall());

0 commit comments

Comments
 (0)