quic: multiple updates to quic impl · nodejs/node@43c25e2
@@ -10,14 +10,18 @@ const {
10101111describe('quic internal endpoint stats and state', { skip: !hasQuic }, () => {
1212const {
13-Endpoint,
13+QuicEndpoint,
1414 QuicStreamState,
1515 QuicStreamStats,
16- SessionState,
17- SessionStats,
18- kFinishClose,
16+ QuicSessionState,
17+ QuicSessionStats,
1918} = require('internal/quic/quic');
201920+const {
21+ kFinishClose,
22+ kPrivateConstructor,
23+} = require('internal/quic/symbols');
24+2125const {
2226 inspect,
2327} = require('util');
@@ -29,7 +33,7 @@ describe('quic internal endpoint stats and state', { skip: !hasQuic }, () => {
2933} = require('node:assert');
30343135it('endpoint state', () => {
32-const endpoint = new Endpoint({
36+const endpoint = new QuicEndpoint({
3337onsession() {},
3438session: {},
3539stream: {},
@@ -62,7 +66,7 @@ describe('quic internal endpoint stats and state', { skip: !hasQuic }, () => {
6266});
63676468it('state is not readable after close', () => {
65-const endpoint = new Endpoint({
69+const endpoint = new QuicEndpoint({
6670onsession() {},
6771session: {},
6872stream: {},
@@ -74,24 +78,25 @@ describe('quic internal endpoint stats and state', { skip: !hasQuic }, () => {
7478});
75797680it('state constructor argument is ArrayBuffer', () => {
77-const endpoint = new Endpoint({
81+const endpoint = new QuicEndpoint({
7882onsession() {},
7983session: {},
8084stream: {},
8185}, {});
8286const Cons = endpoint.state.constructor;
83-throws(() => new Cons(1), {
87+throws(() => new Cons(kPrivateConstructor, 1), {
8488code: 'ERR_INVALID_ARG_TYPE'
8589});
8690});
87918892it('endpoint stats', () => {
89-const endpoint = new Endpoint({
93+const endpoint = new QuicEndpoint({
9094onsession() {},
9195session: {},
9296stream: {},
9397});
949899+strictEqual(typeof endpoint.stats.isConnected, 'boolean');
95100strictEqual(typeof endpoint.stats.createdAt, 'bigint');
96101strictEqual(typeof endpoint.stats.destroyedAt, 'bigint');
97102strictEqual(typeof endpoint.stats.bytesReceived, 'bigint');
@@ -107,6 +112,7 @@ describe('quic internal endpoint stats and state', { skip: !hasQuic }, () => {
107112strictEqual(typeof endpoint.stats.immediateCloseCount, 'bigint');
108113109114deepStrictEqual(Object.keys(endpoint.stats.toJSON()), [
115+'connected',
110116'createdAt',
111117'destroyedAt',
112118'bytesReceived',
@@ -128,25 +134,26 @@ describe('quic internal endpoint stats and state', { skip: !hasQuic }, () => {
128134});
129135130136it('stats are still readble after close', () => {
131-const endpoint = new Endpoint({
137+const endpoint = new QuicEndpoint({
132138onsession() {},
133139session: {},
134140stream: {},
135141}, {});
136142strictEqual(typeof endpoint.stats.toJSON(), 'object');
137143endpoint.stats[kFinishClose]();
144+strictEqual(endpoint.stats.isConnected, false);
138145strictEqual(typeof endpoint.stats.destroyedAt, 'bigint');
139146strictEqual(typeof endpoint.stats.toJSON(), 'object');
140147});
141148142149it('stats constructor argument is ArrayBuffer', () => {
143-const endpoint = new Endpoint({
150+const endpoint = new QuicEndpoint({
144151onsession() {},
145152session: {},
146153stream: {},
147154}, {});
148155const Cons = endpoint.stats.constructor;
149-throws(() => new Cons(1), {
156+throws(() => new Cons(kPrivateConstructor, 1), {
150157code: 'ERR_INVALID_ARG_TYPE',
151158});
152159});
@@ -156,8 +163,8 @@ describe('quic internal endpoint stats and state', { skip: !hasQuic }, () => {
156163// temporarily while the rest of the functionality is being
157164// implemented.
158165it('stream and session states', () => {
159-const streamState = new QuicStreamState(new ArrayBuffer(1024));
160-const sessionState = new SessionState(new ArrayBuffer(1024));
166+const streamState = new QuicStreamState(kPrivateConstructor, new ArrayBuffer(1024));
167+const sessionState = new QuicSessionState(kPrivateConstructor, new ArrayBuffer(1024));
161168162169strictEqual(streamState.finSent, false);
163170strictEqual(streamState.finReceived, false);
@@ -195,8 +202,8 @@ describe('quic internal endpoint stats and state', { skip: !hasQuic }, () => {
195202});
196203197204it('stream and session stats', () => {
198-const streamStats = new QuicStreamStats(new ArrayBuffer(1024));
199-const sessionStats = new SessionStats(new ArrayBuffer(1024));
205+const streamStats = new QuicStreamStats(kPrivateConstructor, new ArrayBuffer(1024));
206+const sessionStats = new QuicSessionStats(kPrivateConstructor, new ArrayBuffer(1024));
200207strictEqual(streamStats.createdAt, undefined);
201208strictEqual(streamStats.receivedAt, undefined);
202209strictEqual(streamStats.ackedAt, undefined);