MCPcopy Index your code
hub / github.com/nodejs/node / testDropNewestDiscards

Function testDropNewestDiscards

test/parallel/test-stream-iter-writable-interop.js:186–207  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

184// =============================================================================
185
186async function testDropNewestDiscards() {
187 const chunks = [];
188 const writable = new Writable({
189 highWaterMark: 5,
190 write(chunk, enc, cb) {
191 chunks.push(Buffer.from(chunk));
192 // Never call cb -- data stays buffered
193 },
194 });
195
196 const writer = fromWritable(writable, { backpressure: 'drop-newest' });
197
198 // First write fills the buffer
199 await writer.write('12345');
200
201 // Second write should be silently discarded (no reject, no block)
202 await writer.write('dropped');
203
204 // Only the first chunk was actually written to the writable
205 assert.strictEqual(chunks.length, 1);
206 assert.strictEqual(chunks[0].toString(), '12345');
207}
208
209// =============================================================================
210// drop-newest: writev discards entire batch when full

Calls 3

fromWritableFunction · 0.85
writeMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected