Files
node/test/parallel/test-quic-stream-limits-uni.mjs
Marten Richter 312c562608 quic: add promise to QuicStream for pending strms
before this PR, it was necessary to poll, if a
stream can not be created immediately due to
flow control.
This PR adds a promise to QuicStream, that fulfills,
when a stream is available and ready.

Signed-off-by: Marten Richter <marten.richter@freenet.de>
PR-URL: https://github.com/nodejs/node/pull/65862
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Tim Perry <pimterry@gmail.com>
2026-09-12 09:03:03 +00:00

70 lines
1.7 KiB
JavaScript

// Flags: --experimental-quic --experimental-stream-iter --no-warnings
// Test: uni stream limits and pending behavior.
// initialMaxStreamsUni = 1 limits concurrent uni streams. The second
// stream is queued as pending and opens after the first closes.
import { hasQuic, skip, mustCall } from '../common/index.mjs';
import assert from 'node:assert';
if (!hasQuic) {
skip('QUIC is not enabled');
}
const { listen, connect } = await import('../common/quic.mjs');
const { bytes } = await import('stream/iter');
const encoder = new TextEncoder();
const allDone = Promise.withResolvers();
let serverStreamCount = 0;
const serverEndpoint = await listen(mustCall((serverSession) => {
serverSession.onstream = mustCall(async (stream) => {
await bytes(stream);
await stream.closed;
if (++serverStreamCount === 2) {
serverSession.close();
allDone.resolve();
}
}, 2);
}), {
transportParams: { initialMaxStreamsUni: 1 },
});
const clientSession = await connect(serverEndpoint.address);
await clientSession.opened;
let opened = 0;
// First uni stream opens immediately.
const s1 = await clientSession.createUnidirectionalStream({
body: encoder.encode('uni 1'),
});
// eslint-disable-next-line node-core/must-call-assert
s1.opened.then(() => {
opened++;
});
// Second uni stream is pending (limit = 1).
const s2 = await clientSession.createUnidirectionalStream({
body: encoder.encode('uni 2'),
});
// eslint-disable-next-line node-core/must-call-assert
s2.opened.then(() => {
opened++;
});
assert.strictEqual(opened, 1);
assert.strictEqual(s2.pending, true);
// Wait for both to complete.
await s1.closed;
await allDone.promise;
assert.strictEqual(opened, 2);
await s2.closed;
await clientSession.close();
await serverEndpoint.close();