Skip to content

Commit 18b0d59

Browse files
committed
tests: reduced memory usage of the client domain tests
1 parent 5cb1d6c commit 18b0d59

File tree

64 files changed

+9408
-10264
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+9408
-10264
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"postversion": "npm install --package-lock-only --ignore-scripts --silent",
5252
"ts-node": "ts-node",
5353
"ts-node-inspect": "node --require ts-node/register --inspect",
54-
"test": "jest",
54+
"test": "node --expose-gc ./node_modules/.bin/jest",
5555
"lint": "eslint '{src,tests,scripts}/**/*.{js,ts,json}' 'benches/**/*.{js,ts}'",
5656
"lintfix": "eslint '{src,tests,scripts}/**/*.{js,ts,json}' 'benches/**/*.{js,ts}' --fix",
5757
"lint-shell": "find ./src ./tests ./scripts -type f -regextype posix-extended -regex '.*\\.(sh)' -exec shellcheck {} +",

shell.nix

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ in
99
nodejs
1010
shellcheck
1111
gitAndTools.gh
12-
awscli2
13-
skopeo
1412
jq
1513
];
1614
PKG_CACHE_PATH = utils.pkgCachePath;

src/nodes/NodeConnectionManager.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ class NodeConnectionManager {
697697
ctx.signal.removeEventListener('abort', onAbort);
698698
};
699699
ctx.signal.addEventListener('abort', onAbort);
700-
void ctx.timer.catch(() => {}).finally(() => onAbort());
700+
const timer = ctx.timer.catch(() => {}).finally(() => onAbort());
701701
let delay = this.connectionHolePunchIntervalTime;
702702
// Setting up established event checking
703703
try {
@@ -710,6 +710,7 @@ class NodeConnectionManager {
710710
}
711711
} finally {
712712
onAbort();
713+
await timer;
713714
}
714715
}
715716

src/rpc/RPCClient.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { WritableStream, ReadableStream } from 'stream/web';
2-
import type { ContextTimed } from '@matrixai/contexts';
2+
import type { ContextTimed, ContextTimedInput } from '@matrixai/contexts';
33
import type {
44
HandlerType,
55
JSONRPCRequestMessage,
@@ -156,7 +156,7 @@ class RPCClient<M extends ClientManifest> {
156156
public async unaryCaller<I extends JSONValue, O extends JSONValue>(
157157
method: string,
158158
parameters: I,
159-
ctx: Partial<ContextTimed> = {},
159+
ctx: Partial<ContextTimedInput> = {},
160160
): Promise<O> {
161161
const callerInterface = await this.duplexStreamCaller<I, O>(method, ctx);
162162
const reader = callerInterface.readable.getReader();
@@ -191,7 +191,7 @@ class RPCClient<M extends ClientManifest> {
191191
public async serverStreamCaller<I extends JSONValue, O extends JSONValue>(
192192
method: string,
193193
parameters: I,
194-
ctx: Partial<ContextTimed> = {},
194+
ctx: Partial<ContextTimedInput> = {},
195195
): Promise<ReadableStream<O>> {
196196
const callerInterface = await this.duplexStreamCaller<I, O>(method, ctx);
197197
const writer = callerInterface.writable.getWriter();
@@ -219,7 +219,7 @@ class RPCClient<M extends ClientManifest> {
219219
@ready(new rpcErrors.ErrorRPCDestroyed())
220220
public async clientStreamCaller<I extends JSONValue, O extends JSONValue>(
221221
method: string,
222-
ctx: Partial<ContextTimed> = {},
222+
ctx: Partial<ContextTimedInput> = {},
223223
): Promise<{
224224
output: Promise<O>;
225225
writable: WritableStream<I>;
@@ -252,7 +252,7 @@ class RPCClient<M extends ClientManifest> {
252252
@ready(new rpcErrors.ErrorRPCDestroyed())
253253
public async duplexStreamCaller<I extends JSONValue, O extends JSONValue>(
254254
method: string,
255-
ctx: Partial<ContextTimed> = {},
255+
ctx: Partial<ContextTimedInput> = {},
256256
): Promise<RPCStream<O, I>> {
257257
const abortController = new AbortController();
258258
const signal = abortController.signal;
@@ -270,11 +270,14 @@ class RPCClient<M extends ClientManifest> {
270270
if (ctx.signal.aborted) abortHandler();
271271
ctx.signal.addEventListener('abort', abortHandler);
272272
}
273-
const timer =
274-
ctx.timer ??
275-
new Timer({
276-
delay: this.streamKeepAliveTimeoutTime,
273+
let timer: Timer;
274+
if (!(ctx.timer instanceof Timer)) {
275+
timer = new Timer({
276+
delay: ctx.timer ?? this.streamKeepAliveTimeoutTime,
277277
});
278+
} else {
279+
timer = ctx.timer;
280+
}
278281
const cleanUp = () => {
279282
// Clean up the timer and signal
280283
if (ctx.timer == null) timer.cancel(timerCleanupReasonSymbol);

src/rpc/types.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { ReadableStream, ReadableWritablePair } from 'stream/web';
2-
import type { ContextTimed } from '@matrixai/contexts';
2+
import type { ContextTimed, ContextTimedInput } from '@matrixai/contexts';
33
import type { Handler } from './handlers';
44
import type {
55
Caller,
@@ -239,28 +239,31 @@ type MiddlewareFactory<FR, FW, RR, RW> = (
239239
type UnaryCallerImplementation<
240240
I extends JSONValue = JSONValue,
241241
O extends JSONValue = JSONValue,
242-
> = (parameters: I, ctx?: Partial<ContextTimed>) => Promise<O>;
242+
> = (parameters: I, ctx?: Partial<ContextTimedInput>) => Promise<O>;
243243

244244
type ServerCallerImplementation<
245245
I extends JSONValue = JSONValue,
246246
O extends JSONValue = JSONValue,
247-
> = (parameters: I, ctx?: Partial<ContextTimed>) => Promise<ReadableStream<O>>;
247+
> = (
248+
parameters: I,
249+
ctx?: Partial<ContextTimedInput>,
250+
) => Promise<ReadableStream<O>>;
248251

249252
type ClientCallerImplementation<
250253
I extends JSONValue = JSONValue,
251254
O extends JSONValue = JSONValue,
252255
> = (
253-
ctx?: Partial<ContextTimed>,
256+
ctx?: Partial<ContextTimedInput>,
254257
) => Promise<{ output: Promise<O>; writable: WritableStream<I> }>;
255258

256259
type DuplexCallerImplementation<
257260
I extends JSONValue = JSONValue,
258261
O extends JSONValue = JSONValue,
259-
> = (ctx?: Partial<ContextTimed>) => Promise<RPCStream<O, I>>;
262+
> = (ctx?: Partial<ContextTimedInput>) => Promise<RPCStream<O, I>>;
260263

261264
type RawCallerImplementation = (
262265
headerParams: JSONValue,
263-
ctx?: Partial<ContextTimed>,
266+
ctx?: Partial<ContextTimedInput>,
264267
) => Promise<RPCStream<Uint8Array, Uint8Array>>;
265268

266269
type ConvertDuplexCaller<T> = T extends DuplexCaller<infer I, infer O>

tests/agent/handlers/nodesHolePunchMessage.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,6 @@ describe('nodesHolePunchMessage', () => {
221221
await nodeGraph.stop();
222222
await nodeManager.stop();
223223
await nodeConnectionManager.stop();
224-
await quicSocket.stop();
225224
await taskManager.stop();
226225
await sigchain.stop();
227226
await acl.stop();

0 commit comments

Comments
 (0)