Files
node/test/parallel/test-quic-internal-setcallbacks.mjs
T
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

52 lines
1.3 KiB
JavaScript

// Flags: --expose-internals --experimental-quic --no-warnings
import { hasQuic, skip } from '../common/index.mjs';
import assert from 'node:assert';
if (!hasQuic) {
skip('QUIC is not enabled');
}
import { default as binding } from 'internal/test/binding';
const quic = binding.internalBinding('quic');
const callbacks = {
onEndpointClose() {},
onSessionNew() {},
onSessionClose() {},
onSessionApplication() {},
onSessionDatagram() {},
onSessionDatagramStatus() {},
onSessionHandshake() {},
onSessionPathValidation() {},
onSessionTicket() {},
onSessionNewToken() {},
onSessionKeyLog() {},
onSessionQlog() {},
onSessionEarlyDataRejected() {},
onSessionOrigin() {},
onSessionGoaway() {},
onSessionVersionNegotiation() {},
onStreamAvailable() {},
onStreamCreated() {},
onStreamBlocked() {},
onStreamClose() {},
onStreamDrain() {},
onStreamReset() {},
onStreamStopSending() {},
onStreamHeaders() {},
onStreamTrailers() {},
};
// Fail if any callback is missing
for (const fn of Object.keys(callbacks)) {
// eslint-disable-next-line no-unused-vars
const { [fn]: _, ...rest } = callbacks;
assert.throws(() => quic.setCallbacks(rest), {
code: 'ERR_MISSING_ARGS',
});
}
// If all callbacks are present it should work
quic.setCallbacks(callbacks);
// Multiple calls should just be ignored.
quic.setCallbacks(callbacks);