mirror of
https://github.com/nodejs/node.git
synced 2026-10-28 10:15:07 +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>
45 lines
1.3 KiB
JavaScript
45 lines
1.3 KiB
JavaScript
// Flags: --experimental-quic --no-warnings
|
|
|
|
// Test: async iterable source error destroys the stream.
|
|
// When the async iterable body source throws, the stream should be
|
|
// destroyed with the error and stream.closed should reject.
|
|
|
|
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 encoder = new TextEncoder();
|
|
|
|
const serverEndpoint = await listen(mustCall(async (serverSession) => {
|
|
await serverSession.closed;
|
|
}), { transportParams: { maxIdleTimeout: 1 } });
|
|
|
|
const clientSession = await connect(serverEndpoint.address, {
|
|
transportParams: { maxIdleTimeout: 1 },
|
|
});
|
|
await clientSession.opened;
|
|
|
|
const testError = new Error('async source error');
|
|
|
|
async function* failingSource() {
|
|
yield encoder.encode('partial ');
|
|
throw testError;
|
|
}
|
|
|
|
const stream = await clientSession.createBidirectionalStream();
|
|
|
|
// Attach the closed handler BEFORE setBody so the rejection from
|
|
// stream.destroy(err) is caught before it becomes unhandled.
|
|
const closedPromise = assert.rejects(stream.closed, testError);
|
|
|
|
stream.setBody(failingSource());
|
|
|
|
// The stream should be destroyed with the source error.
|
|
await Promise.all([closedPromise, clientSession.closed]);
|
|
await serverEndpoint.close();
|