mirror of
https://github.com/nodejs/node.git
synced 2026-11-09 15:11:11 -05:00
Signed-off-by: Antoine du Hamel <duhamelantoine1995@gmail.com> PR-URL: https://github.com/nodejs/node/pull/64716 Reviewed-By: Ethan Arrowood <ethan@arrowood.dev> Reviewed-By: Aviv Keller <me@aviv.sh>
45 lines
1.4 KiB
JavaScript
45 lines
1.4 KiB
JavaScript
// Flags: --experimental-quic --experimental-stream-iter --no-warnings
|
|
|
|
// Test: async rejection in onstream destroys session.
|
|
// safeCallbackInvoke detects the returned promise and attaches a
|
|
// rejection handler that calls session.destroy(err). The error is
|
|
// delivered to the onerror callback.
|
|
|
|
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 testError = new Error('async onstream rejection');
|
|
|
|
const serverEndpoint = await listen(mustCall(async (serverSession) => {
|
|
serverSession.onerror = mustCall((err) => {
|
|
assert.strictEqual(err, testError);
|
|
});
|
|
|
|
serverSession.onstream = async () => {
|
|
throw testError;
|
|
};
|
|
|
|
// Session closed rejects with the error from the async rejection.
|
|
await assert.rejects(serverSession.closed, testError);
|
|
}), { transportParams: { maxIdleTimeout: 1 } });
|
|
|
|
const clientSession = await connect(serverEndpoint.address, {
|
|
transportParams: { maxIdleTimeout: 1 },
|
|
});
|
|
await clientSession.opened;
|
|
|
|
const stream = await clientSession.createBidirectionalStream({
|
|
body: new TextEncoder().encode('trigger onstream'),
|
|
});
|
|
|
|
// The client session closes via CONNECTION_CLOSE or idle timeout
|
|
// after the server session is destroyed by the async rejection.
|
|
await Promise.all([stream.closed, clientSession.closed]);
|
|
await serverEndpoint.close();
|