Skip to content

Commit

Permalink
tests: cleaning up dependencies in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tegefaulkes committed Sep 21, 2022
1 parent 27316f9 commit f1ab40b
Show file tree
Hide file tree
Showing 18 changed files with 205 additions and 133 deletions.
13 changes: 9 additions & 4 deletions src/bootstrap/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import path from 'path';
import Logger from '@matrixai/logger';
import { DB } from '@matrixai/db';
import * as bootstrapErrors from './errors';
import Queue from '../nodes/Queue';
import TaskManager from '../tasks/TaskManager';
import { IdentitiesManager } from '../identities';
import { SessionManager } from '../sessions';
import { Status } from '../status';
Expand Down Expand Up @@ -143,12 +143,16 @@ async function bootstrapState({
keyManager,
logger: logger.getChild(NodeGraph.name),
});
const queue = new Queue({ logger });
const taskManager = await TaskManager.createTaskManager({
db,
logger,
lazy: true,
});
const nodeConnectionManager = new NodeConnectionManager({
keyManager,
nodeGraph,
proxy,
queue,
taskManager,
logger: logger.getChild(NodeConnectionManager.name),
});
const nodeManager = new NodeManager({
Expand All @@ -157,7 +161,7 @@ async function bootstrapState({
nodeGraph,
nodeConnectionManager,
sigchain,
queue,
taskManager,
logger: logger.getChild(NodeManager.name),
});
const notificationsManager =
Expand Down Expand Up @@ -196,6 +200,7 @@ async function bootstrapState({
await acl.stop();
await sigchain.stop();
await identitiesManager.stop();
await taskManager.stop();
await db.stop();
await keyManager.stop();
await schema.stop();
Expand Down
19 changes: 12 additions & 7 deletions tests/agent/GRPCClientAgent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import path from 'path';
import os from 'os';
import Logger, { LogLevel, StreamHandler } from '@matrixai/logger';
import { DB } from '@matrixai/db';
import Queue from '@/nodes/Queue';
import TaskManager from '@/tasks/TaskManager';
import GestaltGraph from '@/gestalts/GestaltGraph';
import ACL from '@/acl/ACL';
import KeyManager from '@/keys/KeyManager';
Expand Down Expand Up @@ -41,7 +41,7 @@ describe(GRPCClientAgent.name, () => {
let keyManager: KeyManager;
let vaultManager: VaultManager;
let nodeGraph: NodeGraph;
let queue: Queue;
let taskManager: TaskManager;
let nodeConnectionManager: NodeConnectionManager;
let nodeManager: NodeManager;
let sigchain: Sigchain;
Expand Down Expand Up @@ -104,12 +104,16 @@ describe(GRPCClientAgent.name, () => {
keyManager,
logger,
});
queue = new Queue({ logger });
taskManager = await TaskManager.createTaskManager({
db,
logger,
lazy: true,
});
nodeConnectionManager = new NodeConnectionManager({
keyManager,
nodeGraph,
proxy,
queue,
taskManager,
logger,
});
nodeManager = new NodeManager({
Expand All @@ -118,12 +122,12 @@ describe(GRPCClientAgent.name, () => {
keyManager: keyManager,
nodeGraph: nodeGraph,
nodeConnectionManager: nodeConnectionManager,
queue,
taskManager,
logger: logger,
});
await queue.start();
await nodeManager.start();
await nodeConnectionManager.start({ nodeManager });
await taskManager.startProcessing();
notificationsManager =
await NotificationsManager.createNotificationsManager({
acl: acl,
Expand Down Expand Up @@ -169,20 +173,21 @@ describe(GRPCClientAgent.name, () => {
});
}, globalThis.defaultTimeout);
afterEach(async () => {
await taskManager.stopProcessing();
await testAgentUtils.closeTestAgentClient(client);
await testAgentUtils.closeTestAgentServer(server);
await vaultManager.stop();
await notificationsManager.stop();
await sigchain.stop();
await nodeConnectionManager.stop();
await nodeManager.stop();
await queue.stop();
await nodeGraph.stop();
await gestaltGraph.stop();
await acl.stop();
await proxy.stop();
await db.stop();
await keyManager.stop();
await taskManager.stop();
await fs.promises.rm(dataDir, {
force: true,
recursive: true,
Expand Down
19 changes: 11 additions & 8 deletions tests/agent/service/notificationsSend.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { createPrivateKey, createPublicKey } from 'crypto';
import { exportJWK, SignJWT } from 'jose';
import Logger, { LogLevel, StreamHandler } from '@matrixai/logger';
import { DB } from '@matrixai/db';
import Queue from '@/nodes/Queue';
import TaskManager from '@/tasks/TaskManager';
import KeyManager from '@/keys/KeyManager';
import GRPCServer from '@/grpc/GRPCServer';
import NodeConnectionManager from '@/nodes/NodeConnectionManager';
Expand Down Expand Up @@ -39,7 +39,7 @@ describe('notificationsSend', () => {
let senderKeyManager: KeyManager;
let dataDir: string;
let nodeGraph: NodeGraph;
let queue: Queue;
let taskManager: TaskManager;
let nodeConnectionManager: NodeConnectionManager;
let nodeManager: NodeManager;
let notificationsManager: NotificationsManager;
Expand Down Expand Up @@ -102,14 +102,16 @@ describe('notificationsSend', () => {
keyManager,
logger: logger.getChild('NodeGraph'),
});
queue = new Queue({
logger: logger.getChild('queue'),
taskManager = await TaskManager.createTaskManager({
db,
logger,
lazy: true,
});
nodeConnectionManager = new NodeConnectionManager({
keyManager,
nodeGraph,
proxy,
queue,
taskManager,
connConnectTime: 2000,
connTimeoutTime: 2000,
logger: logger.getChild('NodeConnectionManager'),
Expand All @@ -120,12 +122,12 @@ describe('notificationsSend', () => {
nodeGraph,
nodeConnectionManager,
sigchain,
queue,
taskManager,
logger,
});
await queue.start();
await nodeManager.start();
await nodeConnectionManager.start({ nodeManager });
await taskManager.startProcessing();
notificationsManager =
await NotificationsManager.createNotificationsManager({
acl,
Expand Down Expand Up @@ -156,11 +158,11 @@ describe('notificationsSend', () => {
});
}, globalThis.defaultTimeout);
afterEach(async () => {
await taskManager.stopProcessing();
await grpcClient.destroy();
await grpcServer.stop();
await notificationsManager.stop();
await nodeConnectionManager.stop();
await queue.stop();
await nodeManager.stop();
await sigchain.stop();
await sigchain.stop();
Expand All @@ -169,6 +171,7 @@ describe('notificationsSend', () => {
await db.stop();
await senderKeyManager.stop();
await keyManager.stop();
await taskManager.stop();
await fs.promises.rm(dataDir, {
force: true,
recursive: true,
Expand Down
19 changes: 11 additions & 8 deletions tests/client/service/gestaltsDiscoveryByIdentity.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import os from 'os';
import Logger, { LogLevel, StreamHandler } from '@matrixai/logger';
import { DB } from '@matrixai/db';
import { Metadata } from '@grpc/grpc-js';
import Queue from '@/nodes/Queue';
import TaskManager from '@/tasks/TaskManager';
import GestaltGraph from '@/gestalts/GestaltGraph';
import ACL from '@/acl/ACL';
import KeyManager from '@/keys/KeyManager';
Expand Down Expand Up @@ -45,7 +45,7 @@ describe('gestaltsDiscoveryByIdentity', () => {
let gestaltGraph: GestaltGraph;
let identitiesManager: IdentitiesManager;
let nodeGraph: NodeGraph;
let queue: Queue;
let taskManager: TaskManager;
let nodeConnectionManager: NodeConnectionManager;
let nodeManager: NodeManager;
let sigchain: Sigchain;
Expand Down Expand Up @@ -113,14 +113,16 @@ describe('gestaltsDiscoveryByIdentity', () => {
keyManager,
logger: logger.getChild('NodeGraph'),
});
queue = new Queue({
logger: logger.getChild('queue'),
taskManager = await TaskManager.createTaskManager({
db,
logger,
lazy: true,
});
nodeConnectionManager = new NodeConnectionManager({
keyManager,
nodeGraph,
proxy,
queue,
taskManager,
connConnectTime: 2000,
connTimeoutTime: 2000,
logger: logger.getChild('NodeConnectionManager'),
Expand All @@ -131,12 +133,12 @@ describe('gestaltsDiscoveryByIdentity', () => {
nodeConnectionManager,
nodeGraph,
sigchain,
queue,
taskManager,
logger,
});
await queue.start();
await nodeManager.start();
await nodeConnectionManager.start({ nodeManager });
await taskManager.startProcessing();
discovery = await Discovery.createDiscovery({
db,
keyManager,
Expand Down Expand Up @@ -167,20 +169,21 @@ describe('gestaltsDiscoveryByIdentity', () => {
});
});
afterEach(async () => {
await taskManager.stopProcessing();
await grpcClient.destroy();
await grpcServer.stop();
await discovery.stop();
await nodeGraph.stop();
await nodeConnectionManager.stop();
await nodeManager.stop();
await queue.stop();
await sigchain.stop();
await proxy.stop();
await identitiesManager.stop();
await gestaltGraph.stop();
await acl.stop();
await db.stop();
await keyManager.stop();
await taskManager.stop();
await fs.promises.rm(dataDir, {
force: true,
recursive: true,
Expand Down
19 changes: 11 additions & 8 deletions tests/client/service/gestaltsDiscoveryByNode.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import os from 'os';
import Logger, { LogLevel, StreamHandler } from '@matrixai/logger';
import { DB } from '@matrixai/db';
import { Metadata } from '@grpc/grpc-js';
import Queue from '@/nodes/Queue';
import TaskManager from '@/tasks/TaskManager';
import GestaltGraph from '@/gestalts/GestaltGraph';
import ACL from '@/acl/ACL';
import KeyManager from '@/keys/KeyManager';
Expand Down Expand Up @@ -46,7 +46,7 @@ describe('gestaltsDiscoveryByNode', () => {
let gestaltGraph: GestaltGraph;
let identitiesManager: IdentitiesManager;
let nodeGraph: NodeGraph;
let queue: Queue;
let taskManager: TaskManager;
let nodeConnectionManager: NodeConnectionManager;
let nodeManager: NodeManager;
let sigchain: Sigchain;
Expand Down Expand Up @@ -114,14 +114,16 @@ describe('gestaltsDiscoveryByNode', () => {
keyManager,
logger: logger.getChild('NodeGraph'),
});
queue = new Queue({
logger: logger.getChild('queue'),
taskManager = await TaskManager.createTaskManager({
db,
logger,
lazy: true,
});
nodeConnectionManager = new NodeConnectionManager({
keyManager,
nodeGraph,
proxy,
queue,
taskManager,
connConnectTime: 2000,
connTimeoutTime: 2000,
logger: logger.getChild('NodeConnectionManager'),
Expand All @@ -132,12 +134,12 @@ describe('gestaltsDiscoveryByNode', () => {
nodeConnectionManager,
nodeGraph,
sigchain,
queue,
taskManager,
logger,
});
await queue.start();
await nodeManager.start();
await nodeConnectionManager.start({ nodeManager });
await taskManager.start();
discovery = await Discovery.createDiscovery({
db,
keyManager,
Expand Down Expand Up @@ -168,20 +170,21 @@ describe('gestaltsDiscoveryByNode', () => {
});
});
afterEach(async () => {
await taskManager.stopProcessing();
await grpcClient.destroy();
await grpcServer.stop();
await discovery.stop();
await nodeGraph.stop();
await nodeConnectionManager.stop();
await nodeManager.stop();
await queue.stop();
await sigchain.stop();
await proxy.stop();
await identitiesManager.stop();
await gestaltGraph.stop();
await acl.stop();
await db.stop();
await keyManager.stop();
await taskManager.stop();
await fs.promises.rm(dataDir, {
force: true,
recursive: true,
Expand Down
Loading

0 comments on commit f1ab40b

Please sign in to comment.