forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest-whatwg-transformstream-cancel-write-race.js
More file actions
54 lines (43 loc) · 1.5 KB
/
test-whatwg-transformstream-cancel-write-race.js
File metadata and controls
54 lines (43 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
'use strict';
const common = require('../common');
const assert = require('assert');
const { TransformStream } = require('stream/web');
const { setTimeout } = require('timers/promises');
// Test for https://github.com/nodejs/node/issues/62036
// A late write racing with reader.cancel() should not throw an
// internal "transformAlgorithm is not a function" TypeError.
async function test() {
const stream = new TransformStream({
transform(chunk, controller) {
controller.enqueue(chunk);
},
});
await setTimeout(0);
const reader = stream.readable.getReader();
const writer = stream.writable.getWriter();
// Release backpressure.
const pendingRead = reader.read();
// Simulate client disconnect / shutdown.
const pendingCancel = reader.cancel(new Error('client disconnected'));
// Late write racing with cancel.
const pendingLateWrite = writer.write('late-write');
const [
readResult,
cancelResult,
lateWriteResult,
] = await Promise.allSettled([
pendingRead,
pendingCancel,
pendingLateWrite,
]);
assert.strictEqual(readResult.status, 'fulfilled');
assert.strictEqual(cancelResult.status, 'fulfilled');
if (lateWriteResult.status === 'rejected') {
const err = lateWriteResult.reason;
const isNotAFunction = err instanceof TypeError &&
/transformAlgorithm is not a function/.test(err.message);
assert.ok(!isNotAFunction,
`Internal implementation error leaked: ${err.message}`);
}
}
test().then(common.mustCall());