|
1 | 1 | import type { Host, Port, TLSConfig } from '@/network/types'; |
2 | | -import { webcrypto } from 'crypto'; |
3 | | -import RPCServer from "../../src/rpc/RPCServer"; |
4 | | -import {NodeId, NodeIdEncoded, NodeIdString} from "@/ids"; |
5 | | -import KeyRing from "@/keys/KeyRing"; |
6 | | -import NodeGraph from "@/nodes/NodeGraph"; |
7 | | -import NodeManager from "@/nodes/NodeManager"; |
8 | | -import {DB} from "@matrixai/db"; |
9 | | -import ACL from "@/acl/ACL"; |
10 | | -import GestaltGraph from "@/gestalts/GestaltGraph"; |
11 | | -import path from "path"; |
12 | | -import Sigchain from "@/sigchain/Sigchain"; |
13 | | -import TaskManager from "@/tasks/TaskManager"; |
14 | | -import fs from "fs"; |
15 | | -import os from "os"; |
16 | | -import {QUICServer, QUICSocket} from "@matrixai/quic"; |
17 | 2 | import type { |
18 | 3 | Crypto as QUICCrypto, |
19 | 4 | Host as QUICHost, |
20 | 5 | } from '@matrixai/quic/dist/types'; |
| 6 | +import type { NodeAddress } from '@/nodes/types'; |
| 7 | +import type { NodeId, NodeIdEncoded, NodeIdString } from '@/ids'; |
| 8 | +import path from 'path'; |
| 9 | +import fs from 'fs'; |
| 10 | +import os from 'os'; |
| 11 | +import { webcrypto } from 'crypto'; |
| 12 | +import { DB } from '@matrixai/db'; |
| 13 | +import { QUICServer, QUICSocket } from '@matrixai/quic'; |
21 | 14 | import Logger, { formatting, LogLevel, StreamHandler } from '@matrixai/logger'; |
| 15 | +import KeyRing from '@/keys/KeyRing'; |
| 16 | +import NodeGraph from '@/nodes/NodeGraph'; |
| 17 | +import NodeManager from '@/nodes/NodeManager'; |
| 18 | +import ACL from '@/acl/ACL'; |
| 19 | +import GestaltGraph from '@/gestalts/GestaltGraph'; |
| 20 | +import Sigchain from '@/sigchain/Sigchain'; |
| 21 | +import TaskManager from '@/tasks/TaskManager'; |
22 | 22 | import * as nodesUtils from '@/nodes/utils'; |
23 | 23 | import * as keysUtils from '@/keys/utils'; |
24 | 24 | import NodeConnectionManager from '@/nodes/NodeConnectionManager'; |
25 | 25 | import { promise, sleep } from '@/utils'; |
26 | | -import * as tlsUtils from '../utils/tls'; |
| 26 | +import * as nodesErrors from '@/nodes/errors'; |
27 | 27 | import NodeConnection from '../../src/nodes/NodeConnection'; |
| 28 | +import RPCServer from '../../src/rpc/RPCServer'; |
| 29 | +import * as tlsUtils from '../utils/tls'; |
28 | 30 |
|
29 | 31 | /** |
30 | 32 | * Signs using the 256-bit HMAC key |
@@ -96,6 +98,7 @@ describe(`${NodeConnectionManager.name} lifecycle test`, () => { |
96 | 98 | let serverSocket: QUICSocket; |
97 | 99 | let quicServer: QUICServer; |
98 | 100 | let rpcServer: RPCServer; |
| 101 | + let serverAddress: NodeAddress; |
99 | 102 | let clientSocket: QUICSocket; |
100 | 103 |
|
101 | 104 | let keyRing: KeyRing; |
@@ -207,11 +210,10 @@ describe(`${NodeConnectionManager.name} lifecycle test`, () => { |
207 | 210 | db, |
208 | 211 | logger, |
209 | 212 | }); |
210 | | - const address = { |
| 213 | + serverAddress = { |
211 | 214 | host: quicServer.host as unknown as Host, |
212 | 215 | port: quicServer.port as unknown as Port, |
213 | 216 | }; |
214 | | - await nodeGraph.setNode(serverNodeId, address); |
215 | 217 | }); |
216 | 218 |
|
217 | 219 | afterEach(async () => { |
@@ -273,6 +275,7 @@ describe(`${NodeConnectionManager.name} lifecycle test`, () => { |
273 | 275 | }); |
274 | 276 |
|
275 | 277 | test('acquireConnection should create connection', async () => { |
| 278 | + await nodeGraph.setNode(serverNodeId, serverAddress); |
276 | 279 | const nodeConnectionManager = new NodeConnectionManager({ |
277 | 280 | keyRing, |
278 | 281 | logger: logger.getChild(NodeConnectionManager.name), |
@@ -313,6 +316,7 @@ describe(`${NodeConnectionManager.name} lifecycle test`, () => { |
313 | 316 | await nodeConnectionManager.stop(); |
314 | 317 | }); |
315 | 318 | test('withConnF should create connection', async () => { |
| 319 | + await nodeGraph.setNode(serverNodeId, serverAddress); |
316 | 320 | const nodeConnectionManager = new NodeConnectionManager({ |
317 | 321 | keyRing, |
318 | 322 | logger: logger.getChild(NodeConnectionManager.name), |
@@ -353,6 +357,7 @@ describe(`${NodeConnectionManager.name} lifecycle test`, () => { |
353 | 357 | await nodeConnectionManager.stop(); |
354 | 358 | }); |
355 | 359 | test('should list active connections', async () => { |
| 360 | + await nodeGraph.setNode(serverNodeId, serverAddress); |
356 | 361 | const nodeConnectionManager = new NodeConnectionManager({ |
357 | 362 | keyRing, |
358 | 363 | logger: logger.getChild(NodeConnectionManager.name), |
@@ -401,6 +406,7 @@ describe(`${NodeConnectionManager.name} lifecycle test`, () => { |
401 | 406 | await nodeConnectionManager.stop(); |
402 | 407 | }); |
403 | 408 | test('withConnG should create connection', async () => { |
| 409 | + await nodeGraph.setNode(serverNodeId, serverAddress); |
404 | 410 | const nodeConnectionManager = new NodeConnectionManager({ |
405 | 411 | keyRing, |
406 | 412 | logger: logger.getChild(NodeConnectionManager.name), |
@@ -436,9 +442,16 @@ describe(`${NodeConnectionManager.name} lifecycle test`, () => { |
436 | 442 | // @ts-ignore: kidnap protected property |
437 | 443 | const connectionMap = nodeConnectionManager.connections; |
438 | 444 |
|
439 | | - await nodeConnectionManager.withConnG(serverNodeId, async function* () { |
440 | | - expect(connectionMap.size).toBeGreaterThanOrEqual(1); |
441 | | - }); |
| 445 | + const gen = nodeConnectionManager.withConnG( |
| 446 | + serverNodeId, |
| 447 | + async function* (): AsyncGenerator { |
| 448 | + expect(connectionMap.size).toBeGreaterThanOrEqual(1); |
| 449 | + }, |
| 450 | + ); |
| 451 | + |
| 452 | + for await (const _ of gen) { |
| 453 | + // Do nothing |
| 454 | + } |
442 | 455 |
|
443 | 456 | await nodeConnectionManager.stop(); |
444 | 457 | }); |
@@ -480,16 +493,26 @@ describe(`${NodeConnectionManager.name} lifecycle test`, () => { |
480 | 493 | const randomNodeId = keysUtils.publicKeyToNodeId( |
481 | 494 | keysUtils.generateKeyPair().publicKey, |
482 | 495 | ); |
483 | | - const gen = nodeConnectionManager.withConnG(randomNodeId, async function* (): AsyncGenerator { |
484 | | - expect(connectionMap.size).toBeGreaterThanOrEqual(1); |
485 | | - }); |
486 | | - for await (const _ of gen) { |
487 | | - //do nothing |
488 | | - } |
| 496 | + const gen = nodeConnectionManager.withConnG( |
| 497 | + randomNodeId, |
| 498 | + async function* (): AsyncGenerator { |
| 499 | + expect(connectionMap.size).toBeGreaterThanOrEqual(1); |
| 500 | + }, |
| 501 | + ); |
| 502 | + |
| 503 | + const prom = async () => { |
| 504 | + for await (const _ of gen) { |
| 505 | + // Do nothing |
| 506 | + } |
| 507 | + }; |
| 508 | + await expect(prom).rejects.toThrow( |
| 509 | + nodesErrors.ErrorNodeGraphNodeIdNotFound, |
| 510 | + ); |
489 | 511 |
|
490 | 512 | await nodeConnectionManager.stop(); |
491 | 513 | }); |
492 | 514 | test('connection should persist', async () => { |
| 515 | + await nodeGraph.setNode(serverNodeId, serverAddress); |
493 | 516 | const nodeConnectionManager = new NodeConnectionManager({ |
494 | 517 | keyRing, |
495 | 518 | logger: logger.getChild(NodeConnectionManager.name), |
@@ -536,6 +559,7 @@ describe(`${NodeConnectionManager.name} lifecycle test`, () => { |
536 | 559 | await nodeConnectionManager.stop(); |
537 | 560 | }); |
538 | 561 | test('should create 1 connection with concurrent creates', async () => { |
| 562 | + await nodeGraph.setNode(serverNodeId, serverAddress); |
539 | 563 | const nodeConnectionManager = new NodeConnectionManager({ |
540 | 564 | keyRing, |
541 | 565 | logger: logger.getChild(NodeConnectionManager.name), |
@@ -590,6 +614,7 @@ describe(`${NodeConnectionManager.name} lifecycle test`, () => { |
590 | 614 | await nodeConnectionManager.stop(); |
591 | 615 | }); |
592 | 616 | test('should destroy a connection', async () => { |
| 617 | + await nodeGraph.setNode(serverNodeId, serverAddress); |
593 | 618 | const nodeConnectionManager = new NodeConnectionManager({ |
594 | 619 | keyRing, |
595 | 620 | logger: logger.getChild(NodeConnectionManager.name), |
@@ -643,6 +668,7 @@ describe(`${NodeConnectionManager.name} lifecycle test`, () => { |
643 | 668 | await nodeConnectionManager.stop(); |
644 | 669 | }); |
645 | 670 | test('stopping should destroy all connections', async () => { |
| 671 | + await nodeGraph.setNode(serverNodeId, serverAddress); |
646 | 672 | const nodeConnectionManager = new NodeConnectionManager({ |
647 | 673 | keyRing, |
648 | 674 | logger: logger.getChild(NodeConnectionManager.name), |
|
0 commit comments