Skip to content

Commit 43ea335

Browse files
committed
chore: cleaned up types and errors
1 parent c363f0e commit 43ea335

File tree

5 files changed

+4040
-31
lines changed

5 files changed

+4040
-31
lines changed

span.jsonl

Lines changed: 0 additions & 20 deletions
This file was deleted.

src/errors.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
import type { POJO } from '@matrixai/errors';
1+
import type { POJO } from './types.js';
22
import type { ConnectionError, CryptoError } from './native/types.js';
33
import { AbstractError } from '@matrixai/errors';
44

55
class ErrorQUIC<T> extends AbstractError<T> {
66
static description = 'QUIC error';
77
}
88

9-
class ErrorQUICUndefinedBehaviour<T> extends AbstractError<T> {
9+
class ErrorQUICUndefinedBehaviour<T> extends ErrorQUIC<T> {
1010
static description = 'You should never see this error';
1111
}
1212

13-
class ErrorQUICHostInvalid<T> extends AbstractError<T> {
13+
class ErrorQUICHostInvalid<T> extends ErrorQUIC<T> {
1414
static description = 'Host provided was not valid';
1515
}
1616

17-
class ErrorQUICPortInvalid<T> extends AbstractError<T> {
17+
class ErrorQUICPortInvalid<T> extends ErrorQUIC<T> {
1818
static description = 'Port provided was not valid';
1919
}
2020

src/types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import type QUICStream from './QUICStream.js';
22
import type { CryptoError } from './native/types.js';
33

4+
type POJO = { [key: string]: any };
5+
46
/**
57
* Opaque types are wrappers of existing types
68
* that require smart constructors
@@ -350,6 +352,7 @@ type StreamCodeToReason = (type: 'read' | 'write', code: number) => any;
350352
type QUICStreamMap = Map<StreamId, QUICStream>;
351353

352354
export type {
355+
POJO,
353356
Opaque,
354357
Class,
355358
Callback,

memtest.ts renamed to tests/memtest.ts

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,27 @@
11
import type { ClientCryptoOps, ServerCryptoOps } from '#types.js';
2-
import Logger, { formatting, LogLevel, StreamHandler } from '@matrixai/logger';
3-
import * as testsUtils from './tests/utils.js';
4-
import { generateTLSConfig } from './tests/utils.js';
2+
import Logger, {
3+
formatting,
4+
LogLevel,
5+
StreamHandler,
6+
tracer,
7+
} from '@matrixai/logger';
58
import * as events from '#events.js';
69
import * as utils from '#utils.js';
10+
import * as testsUtils from './utils.js';
711
import QUICServer from '#QUICServer.js';
812
import QUICClient from '#QUICClient.js';
913
import QUICStream from '#QUICStream.js';
1014

15+
const p = (async () => {
16+
const fs = await import('node:fs');
17+
const spanFile = await fs.promises.open('span.jsonl', 'w');
18+
const gen = tracer.streamEvents();
19+
for await (const event of gen) {
20+
await spanFile.write(JSON.stringify(event) + '\n');
21+
}
22+
await spanFile.close();
23+
})();
24+
1125
const main = async () => {
1226
const logger = new Logger(`${QUICStream.name} Test`, LogLevel.WARN, [
1327
new StreamHandler(
@@ -25,10 +39,8 @@ const main = async () => {
2539
randomBytes: testsUtils.randomBytes,
2640
};
2741
const message = Buffer.from('The Quick Brown Fox Jumped Over The Lazy Dog');
28-
const numStreams = 10;
29-
const numMessage = 10;
3042
const connectionEventProm = utils.promise<events.EventQUICServerConnection>();
31-
const tlsConfig = await generateTLSConfig('RSA');
43+
const tlsConfig = await testsUtils.generateTLSConfig('RSA');
3244
const server = new QUICServer({
3345
crypto: {
3446
key,
@@ -75,7 +87,7 @@ const main = async () => {
7587
);
7688

7789
// Let's make a new streams.
78-
for (let i = 0; i < 100000; i++) {
90+
for (let i = 0; i < 1000; i++) {
7991
const stream = client.connection.newStream();
8092
const writer = stream.writable.getWriter();
8193
const reader = stream.readable.getReader();
@@ -100,6 +112,8 @@ const main = async () => {
100112

101113
await client.destroy({ force: true });
102114
await server.stop({ force: true });
115+
tracer.endTracing();
116+
await p;
103117
console.error('Test passed!');
104118
};
105119

0 commit comments

Comments
 (0)