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

Function testRingbufferGrow

test/parallel/test-stream-iter-broadcast-coverage.js:76–97  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

74
75// Ringbuffer grow — push > 16 items without consumer draining
76async function testRingbufferGrow() {
77 const { writer, broadcast: bc } = broadcast({ highWaterMark: 32 });
78 const consumer = bc.push();
79
80 // Push 20 items (exceeds default ringbuffer capacity of 16)
81 for (let i = 0; i < 20; i++) {
82 writer.writeSync(new Uint8Array([i]));
83 }
84 writer.endSync();
85
86 // Read all items back and verify order
87 const items = [];
88 for await (const batch of consumer) {
89 for (const chunk of batch) {
90 items.push(chunk[0]);
91 }
92 }
93 assert.strictEqual(items.length, 20);
94 for (let i = 0; i < 20; i++) {
95 assert.strictEqual(items[i], i);
96 }
97}
98
99// Multiple consumers at the minimum cursor should trim only after the last
100// one advances or detaches.

Calls 4

broadcastFunction · 0.50
pushMethod · 0.45
writeSyncMethod · 0.45
endSyncMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…