node/test/parallel/test-quic-callback-error-onnewtoken.mjs
James M Snell cf91d181fb quic: complete the internal implementation of QUIC
Signed-off-by: James M Snell <jasnell@gmail.com>
Assisted-by: Opencode:Opus 4.6
PR-URL: https://github.com/nodejs/node/pull/62876
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Robert Nagy <ronagy@icloud.com>
2026-05-05 19:16:19 -07:00

42 lines
1.3 KiB
JavaScript

// Flags: --experimental-quic --no-warnings
// Test: onnewtoken callback error handling.
// A sync throw in onnewtoken destroys the session via safeCallbackInvoke.
// The server submits a NEW_TOKEN after handshake completes; the client
// receives it via the onnewtoken callback. Since the session ticket and
// NEW_TOKEN both arrive after the handshake, session.opened is already
// resolved and there is no unhandled rejection / uncaught exception.
import { hasQuic, skip, mustCall } from '../common/index.mjs';
import assert from 'node:assert';
const { rejects, strictEqual } = assert;
if (!hasQuic) {
skip('QUIC is not enabled');
}
const { listen, connect } = await import('../common/quic.mjs');
const testError = new Error('onnewtoken throw');
const serverEndpoint = await listen(mustCall(async (serverSession) => {
await serverSession.closed;
}), { transportParams: { maxIdleTimeout: 1 } });
const clientSession = await connect(serverEndpoint.address, {
transportParams: { maxIdleTimeout: 1 },
onnewtoken() {
throw testError;
},
onerror: mustCall((err) => {
strictEqual(err, testError);
}),
});
await clientSession.opened;
// The session's closed should reject with the error from the throw.
await rejects(clientSession.closed, testError);
await serverEndpoint.close();