Skip to content

Commit 30daec8

Browse files
committed
tests: expanding native stream tests
[ci skip]
1 parent 798014b commit 30daec8

File tree

3 files changed

+2542
-25
lines changed

3 files changed

+2542
-25
lines changed

src/native/types.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -313,11 +313,9 @@ type PathStatsIter = {
313313
[Symbol.iterator](): Iterator<PathStats, void, void>;
314314
};
315315

316+
export { CongestionControlAlgorithm, Shutdown, Type, ConnectionErrorCode };
317+
316318
export type {
317-
CongestionControlAlgorithm,
318-
Shutdown,
319-
Type,
320-
ConnectionErrorCode,
321319
ConnectionError,
322320
Stats,
323321
HostPort as Host,

src/utils.ts

+42
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type {
77
Hostname,
88
ServerCrypto,
99
} from './types';
10+
import type { Connection } from '@/native';
1011
import dns from 'dns';
1112
import { IPv4, IPv6, Validator } from 'ip-num';
1213
import QUICConnectionId from './QUICConnectionId';
@@ -387,6 +388,46 @@ async function sleep(ms: number): Promise<void> {
387388
return await new Promise<void>((r) => setTimeout(r, ms));
388389
}
389390

391+
/**
392+
* Useful for debug printing stream state
393+
*/
394+
function streamStats(
395+
connection: Connection,
396+
streamId: number,
397+
label: string,
398+
): string {
399+
let streamWritable: string;
400+
try {
401+
streamWritable = `${connection.streamWritable(streamId, 0)}`;
402+
} catch (e) {
403+
streamWritable = `threw ${e.message}`;
404+
}
405+
let streamCapacity: string;
406+
try {
407+
streamCapacity = `${connection.streamCapacity(streamId)}`;
408+
} catch (e) {
409+
streamCapacity = `threw ${e.message}`;
410+
}
411+
let readableIterator = false;
412+
for (const streamIterElement of connection.readable()) {
413+
if (streamIterElement === streamId) readableIterator = true;
414+
}
415+
let writableIterator = false;
416+
for (const streamIterElement of connection.writable()) {
417+
if (streamIterElement === streamId) writableIterator = true;
418+
}
419+
return `
420+
---${label}---
421+
isReadable: ${connection.isReadable()},
422+
readable iterator: ${readableIterator},
423+
streamReadable: ${connection.streamReadable(streamId)},
424+
streamFinished: ${connection.streamFinished(streamId)},
425+
writable iterator: ${writableIterator},
426+
streamWritable: ${streamWritable},
427+
streamCapacity: ${streamCapacity},
428+
`;
429+
}
430+
390431
export {
391432
isIPv4,
392433
isIPv6,
@@ -413,4 +454,5 @@ export {
413454
mintToken,
414455
validateToken,
415456
sleep,
457+
streamStats,
416458
};

0 commit comments

Comments
 (0)