node/test/parallel/test-quic-internal-endpoint-listen-defaults.js
James M Snell cdae315706 quic: start adding in the internal quic js api
While the external API for QUIC is expected to be
the WebTransport API primarily, this provides the
internal API for QUIC that aligns with the native
C++ QUIC components.

PR-URL: https://github.com/nodejs/node/pull/53256
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
2024-09-29 11:41:03 -07:00

77 lines
1.7 KiB
JavaScript

// Flags: --expose-internals --no-warnings
'use strict';
const { hasQuic } = require('../common');
const {
describe,
it,
} = require('node:test');
describe('quic internal endpoint listen defaults', { skip: !hasQuic }, async () => {
const {
ok,
strictEqual,
throws,
} = require('node:assert');
const {
SocketAddress,
} = require('net');
const {
Endpoint,
} = require('internal/quic/quic');
it('are reasonable and work as expected', async () => {
const endpoint = new Endpoint({
onsession() {},
session: {},
stream: {},
}, {});
ok(!endpoint.state.isBound);
ok(!endpoint.state.isReceiving);
ok(!endpoint.state.isListening);
strictEqual(endpoint.address, undefined);
throws(() => endpoint.listen(123), {
code: 'ERR_INVALID_ARG_TYPE',
});
endpoint.listen();
throws(() => endpoint.listen(), {
code: 'ERR_INVALID_STATE',
});
ok(endpoint.state.isBound);
ok(endpoint.state.isReceiving);
ok(endpoint.state.isListening);
const address = endpoint.address;
ok(address instanceof SocketAddress);
strictEqual(address.address, '127.0.0.1');
strictEqual(address.family, 'ipv4');
strictEqual(address.flowlabel, 0);
ok(address.port !== 0);
ok(!endpoint.destroyed);
endpoint.destroy();
strictEqual(endpoint.closed, endpoint.close());
await endpoint.closed;
ok(endpoint.destroyed);
throws(() => endpoint.listen(), {
code: 'ERR_INVALID_STATE',
});
throws(() => { endpoint.busy = true; }, {
code: 'ERR_INVALID_STATE',
});
await endpoint[Symbol.asyncDispose]();
strictEqual(endpoint.address, undefined);
});
});