mirror of
https://github.com/nodejs/node.git
synced 2026-10-28 10:15:07 +08:00
Replaces the `for await (const _ of source) {}` discard idiom with
dump(), which says what it does and does not need an eslint-disable
for the unused loop variable. The eslint-disable directives and
comments that become redundant are removed with it.
Only files that already declare --experimental-stream-iter are
converted, so no test gains an experimental flag it did not already
opt into. Files still using the old idiom are left as they are;
converting them would change what those tests run under and belongs
in a separate discussion.
Loops that break early are left alone: those cancel the source rather
than reading it to completion, which is not what dump() does.
Assisted-by: Claude Opus 5
Signed-off-by: Ethan Arrowood <ethan@arrowood.dev>
PR-URL: https://github.com/nodejs/node/pull/65598
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Tim Perry <pimterry@gmail.com>
57 lines
1.8 KiB
JavaScript
57 lines
1.8 KiB
JavaScript
// Flags: --experimental-quic --experimental-stream-iter --no-warnings
|
|
|
|
// Test: pending streams.
|
|
// Stream created before handshake completes, opens after.
|
|
// stream.pending is true before open, false after.
|
|
|
|
import { hasQuic, skip, mustCall } from '../common/index.mjs';
|
|
import assert from 'node:assert';
|
|
import { dump } from 'node:stream/iter';
|
|
|
|
if (!hasQuic) {
|
|
skip('QUIC is not enabled');
|
|
}
|
|
|
|
const { listen, connect } = await import('../common/quic.mjs');
|
|
const { bytes } = await import('stream/iter');
|
|
|
|
const encoder = new TextEncoder();
|
|
|
|
const serverDone = Promise.withResolvers();
|
|
|
|
const serverEndpoint = await listen(mustCall((serverSession) => {
|
|
serverSession.onstream = mustCall(async (stream) => {
|
|
const received = await bytes(stream);
|
|
assert.strictEqual(new TextDecoder().decode(received), 'pending stream');
|
|
stream.writer.endSync();
|
|
await stream.closed;
|
|
serverSession.close();
|
|
serverDone.resolve();
|
|
});
|
|
}));
|
|
|
|
const clientSession = await connect(serverEndpoint.address);
|
|
|
|
// Create a stream BEFORE awaiting opened — the handshake may not have
|
|
// completed yet. The stream should be created in a pending state.
|
|
const stream = await clientSession.createBidirectionalStream({
|
|
body: encoder.encode('pending stream'),
|
|
});
|
|
|
|
// The stream should initially be pending (no ID assigned yet).
|
|
// On fast machines the handshake might already be done.
|
|
assert.strictEqual(typeof stream.pending, 'boolean');
|
|
|
|
// The server's onstream fires only after the handshake completes AND
|
|
// the pending stream opens. By the time we get data on the server,
|
|
// the stream is definitely no longer pending.
|
|
await serverDone.promise;
|
|
|
|
// After the server received data, the stream opened successfully.
|
|
// The data arrival proves (pending stream opens after handshake).
|
|
|
|
await dump(stream);
|
|
await stream.closed;
|
|
await clientSession.close();
|
|
await serverEndpoint.close();
|