MCPcopy Create free account
hub / github.com/nodejs/node / testDestroyDuringBackpressure

Function testDestroyDuringBackpressure

test/parallel/test-stream-iter-to-readable.js:177–204  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

175// =============================================================================
176
177async function testDestroyDuringBackpressure() {
178 let returnCalled = false;
179 async function* gen() {
180 try {
181 // Yield a large batch that will trigger backpressure with HWM=1
182 yield [Buffer.from('a'), Buffer.from('b'), Buffer.from('c')];
183 // This should never be reached
184 yield [Buffer.from('d')];
185 } finally {
186 returnCalled = true;
187 }
188 }
189
190 const readable = toReadable(gen(), { highWaterMark: 1 });
191
192 // Read one chunk to start the pump, then destroy while it's waiting
193 const chunk = await new Promise((resolve) => {
194 readable.once('readable', () => resolve(readable.read()));
195 });
196 assert.ok(chunk);
197
198 // The pump should be waiting on backpressure now. Destroy the stream.
199 readable.destroy();
200
201 await new Promise((resolve) => readable.on('close', resolve));
202 assert.ok(readable.destroyed);
203 assert.ok(returnCalled, 'iterator.return() should have been called');
204}
205
206// =============================================================================
207// fromStreamIter: large data integrity

Callers 1

Calls 8

toReadableFunction · 0.85
genFunction · 0.70
resolveFunction · 0.50
onceMethod · 0.45
readMethod · 0.45
okMethod · 0.45
destroyMethod · 0.45
onMethod · 0.45

Tested by

no test coverage detected