Skip to content

Commit 835d19f

Browse files
committed
wip: NodeConnectionManager lifecycle tests
[ci skip]
1 parent 6a38062 commit 835d19f

3 files changed

Lines changed: 827 additions & 7 deletions

File tree

src/nodes/NodeConnectionManager.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import type { ContextTimed } from '@matrixai/contexts';
44
import type KeyRing from '../keys/KeyRing';
55
import type { Host, Hostname, Port } from '../network/types';
66
import type NodeGraph from './NodeGraph';
7-
import type TaskManager from '../tasks/TaskManager';
87
import type {
98
NodeAddress,
109
NodeData,
@@ -69,7 +68,6 @@ class NodeConnectionManager {
6968
protected logger: Logger;
7069
protected nodeGraph: NodeGraph;
7170
protected keyRing: KeyRing;
72-
protected taskManager: TaskManager;
7371
protected quicSocket: QUICSocket;
7472
// NodeManager has to be passed in during start to allow co-dependency
7573
protected nodeManager: NodeManager | undefined;
@@ -98,7 +96,6 @@ class NodeConnectionManager {
9896
public constructor({
9997
keyRing,
10098
nodeGraph,
101-
taskManager,
10299
quicSocket,
103100
quicClientConfig,
104101
seedNodes = {},
@@ -110,7 +107,6 @@ class NodeConnectionManager {
110107
}: {
111108
nodeGraph: NodeGraph;
112109
keyRing: KeyRing;
113-
taskManager: TaskManager;
114110
quicSocket: QUICSocket;
115111
quicClientConfig: QUICClientConfig;
116112
seedNodes?: SeedNodes;
@@ -123,7 +119,6 @@ class NodeConnectionManager {
123119
this.logger = logger ?? new Logger(NodeConnectionManager.name);
124120
this.keyRing = keyRing;
125121
this.nodeGraph = nodeGraph;
126-
this.taskManager = taskManager;
127122
this.quicSocket = quicSocket;
128123
this.quicClientConfig = quicClientConfig;
129124
const localNodeIdEncoded = nodesUtils.encodeNodeId(keyRing.getNodeId());
@@ -154,12 +149,17 @@ class NodeConnectionManager {
154149
public async stop() {
155150
this.logger.info(`Stopping ${this.constructor.name}`);
156151
this.nodeManager = undefined;
152+
const destroyProms: Array<Promise<void>> = [];
157153
for (const [nodeId, connAndLock] of this.connections) {
158154
if (connAndLock == null) continue;
159155
if (connAndLock.connection == null) continue;
160156
// It exists so we want to destroy it
161-
await this.destroyConnection(IdInternal.fromString<NodeId>(nodeId));
157+
const destroyProm = this.destroyConnection(
158+
IdInternal.fromString<NodeId>(nodeId),
159+
);
160+
destroyProms.push(destroyProm);
162161
}
162+
await Promise.all(destroyProms);
163163
this.logger.info(`Stopped ${this.constructor.name}`);
164164
}
165165

tests/nodes/NodeConnection.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ async function verify(key: ArrayBuffer, data: ArrayBuffer, sig: ArrayBuffer) {
5555
return webcrypto.subtle.verify('HMAC', cryptoKey, sig, data);
5656
}
5757

58-
describe('${NodeConnection.name}', () => {
58+
describe(`${NodeConnection.name}`, () => {
5959
const logger = new Logger(`${NodeConnection.name} test`, LogLevel.WARN, [
6060
new StreamHandler(
6161
formatting.format`${formatting.level}:${formatting.keys}:${formatting.msg}`,

0 commit comments

Comments
 (0)