mirror of
https://github.com/nodejs/node.git
synced 2026-10-28 18:25:13 +08: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>
64 lines
2.0 KiB
JavaScript
64 lines
2.0 KiB
JavaScript
// Flags: --experimental-quic --experimental-stream-iter --no-warnings
|
|
|
|
// Test: RESET_STREAM and STOP_SENDING.
|
|
// server's onreset fires with that code.
|
|
// NOTE: CTRL-01/CTRL-08 (stopSending with specific code) is tested
|
|
// separately because it requires a second endpoint.
|
|
|
|
import { hasQuic, skip, mustCall } from '../common/index.mjs';
|
|
import * as assert from 'node:assert';
|
|
|
|
if (!hasQuic) {
|
|
skip('QUIC is not enabled');
|
|
}
|
|
|
|
const { listen, connect } = await import('../common/quic.mjs');
|
|
|
|
const encoder = new TextEncoder();
|
|
|
|
const serverDone = Promise.withResolvers();
|
|
const serverReady = Promise.withResolvers();
|
|
|
|
const serverEndpoint = await listen(mustCall((serverSession) => {
|
|
serverSession.onstream = mustCall((stream) => {
|
|
// The server's stream.closed will reject when the session is
|
|
// gracefully closed after the peer's reset.
|
|
assert.rejects(stream.closed, (error) => {
|
|
assert.strictEqual(error.code, 'ERR_QUIC_APPLICATION_ERROR');
|
|
return true;
|
|
}).then(mustCall());
|
|
|
|
stream.onreset = mustCall((error) => {
|
|
// The error is the raw close tuple: [type, code, reason].
|
|
assert.strictEqual(error.code, 'ERR_QUIC_APPLICATION_ERROR');
|
|
assert.ok(error.message.includes('42'));
|
|
serverSession.close();
|
|
serverDone.resolve();
|
|
});
|
|
serverReady.resolve();
|
|
});
|
|
}));
|
|
|
|
const clientSession = await connect(serverEndpoint.address);
|
|
await clientSession.opened;
|
|
|
|
const stream = await clientSession.createBidirectionalStream({
|
|
body: encoder.encode('will be reset'),
|
|
});
|
|
|
|
// Wait for the server to receive the stream before resetting.
|
|
await serverReady.promise;
|
|
stream.resetStream(42n);
|
|
|
|
await serverDone.promise;
|
|
// After the server closes (sending CONNECTION_CLOSE), the client
|
|
// session enters draining and all streams are destroyed. The client's
|
|
// stream.closed rejects with the reset code.
|
|
await assert.rejects(stream.closed, (error) => {
|
|
assert.strictEqual(error.code, 'ERR_QUIC_APPLICATION_ERROR');
|
|
assert.ok(error.message.includes('42'));
|
|
return true;
|
|
});
|
|
await clientSession.closed;
|
|
await serverEndpoint.close();
|