Skip to content

Commit

Permalink
fix: workerManager related bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
tegefaulkes committed Feb 14, 2023
1 parent dab5cd8 commit aaaae01
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 58 deletions.
2 changes: 1 addition & 1 deletion src/PolykeyAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import process from 'process';
import Logger from '@matrixai/logger';
import { DB } from '@matrixai/db';
import { CreateDestroyStartStop } from '@matrixai/async-init/dist/CreateDestroyStartStop';
import { WorkerManager } from '@matrixai/workers';
import { WorkerManager } from './workers';
import * as networkUtils from './network/utils';
import KeyRing from './keys/KeyRing';
import CertManager from './keys/CertManager';
Expand Down
1 change: 0 additions & 1 deletion src/bin/agent/CommandStart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ class CommandStart extends CommandPolykey {
const messageIn: AgentChildProcessInput = {
logLevel: this.logger.getEffectiveLevel(),
format: options.format,
workers: options.workers,
agentConfig,
};
agentProcess.send(messageIn, (e) => {
Expand Down
12 changes: 0 additions & 12 deletions src/bin/polykey-agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* @module
*/
import type { AgentChildProcessInput, AgentChildProcessOutput } from './types';
import type { PolykeyWorkerManagerInterface } from '../workers/types';
import fs from 'fs';
import process from 'process';
/**
Expand All @@ -23,7 +22,6 @@ import Logger, { StreamHandler, formatting } from '@matrixai/logger';
import * as binUtils from './utils';
import PolykeyAgent from '../PolykeyAgent';
import * as nodesUtils from '../nodes/utils';
import { WorkerManager, utils as workersUtils } from '../workers';
import ErrorPolykey from '../ErrorPolykey';
import grpcSetLogger from '../grpc/utils/setLogger';
import { promisify, promise } from '../utils';
Expand Down Expand Up @@ -57,10 +55,7 @@ async function main(_argv = process.argv): Promise<number> {
// Set the global upstream GRPC logger
grpcSetLogger(logger.getChild('grpc'));
let pkAgent: PolykeyAgent;
let workerManager: PolykeyWorkerManagerInterface;
exitHandlers.handlers.push(async () => {
pkAgent?.unsetWorkerManager();
await workerManager?.destroy();
await pkAgent?.stop();
});
try {
Expand All @@ -69,13 +64,6 @@ async function main(_argv = process.argv): Promise<number> {
logger: logger.getChild(PolykeyAgent.name),
...messageIn.agentConfig,
});
if (messageIn.workers !== 0) {
workerManager = await workersUtils.createWorkerManager({
cores: messageIn.workers,
logger: logger.getChild(WorkerManager.name),
});
pkAgent.setWorkerManager(workerManager);
}
} catch (e) {
if (e instanceof ErrorPolykey) {
process.stderr.write(
Expand Down
1 change: 1 addition & 0 deletions tests/PolykeyAgent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ describe('PolykeyAgent', () => {
passwordMemLimit: keysUtils.passwordMemLimits.min,
strictMemoryLock: false,
},
workers: 0,
});
let nodePathContents = await fs.promises.readdir(nodePath);
expect(nodePathContents).toContain(config.defaults.statusBase);
Expand Down
35 changes: 17 additions & 18 deletions tests/bin/agent/start.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe('start', () => {
'--proxy-host',
'127.0.0.1',
'--workers',
'0',
'none',
'--verbose',
'--format',
'json',
Expand Down Expand Up @@ -124,7 +124,7 @@ describe('start', () => {
'--background-err-file',
path.join(dataDir, 'err.log'),
'--workers',
'0',
'none',
'--verbose',
'--format',
'json',
Expand Down Expand Up @@ -223,7 +223,7 @@ describe('start', () => {
'--proxy-host',
'127.0.0.1',
'--workers',
'0',
'none',
'--verbose',
'--format',
'json',
Expand All @@ -249,7 +249,7 @@ describe('start', () => {
'--proxy-host',
'127.0.0.1',
'--workers',
'0',
'none',
'--verbose',
'--format',
'json',
Expand Down Expand Up @@ -323,7 +323,7 @@ describe('start', () => {
'--proxy-host',
'127.0.0.1',
'--workers',
'0',
'none',
'--verbose',
'--format',
'json',
Expand Down Expand Up @@ -385,7 +385,6 @@ describe('start', () => {
errorStatusLocked,
]);
bootstrapProcess.kill('SIGTERM');
} else if (index === 1) {
testUtils.expectProcessError(exitCode!, stdErrLine2, [
errorStatusLocked,
]);
Expand All @@ -409,7 +408,7 @@ describe('start', () => {
'--proxy-host',
'127.0.0.1',
'--workers',
'0',
'none',
'--verbose',
],
{
Expand Down Expand Up @@ -439,7 +438,7 @@ describe('start', () => {
'--proxy-host',
'127.0.0.1',
'--workers',
'0',
'none',
'--verbose',
],
{
Expand Down Expand Up @@ -487,7 +486,7 @@ describe('start', () => {
'--proxy-host',
'127.0.0.1',
'--workers',
'0',
'none',
'--verbose',
],
{
Expand Down Expand Up @@ -528,7 +527,7 @@ describe('start', () => {
'--proxy-host',
'127.0.0.1',
'--workers',
'0',
'none',
'--fresh',
'--verbose',
'--format',
Expand Down Expand Up @@ -615,7 +614,7 @@ describe('start', () => {
'--proxy-host',
'127.0.0.1',
'--workers',
'0',
'none',
'--verbose',
'--format',
'json',
Expand Down Expand Up @@ -655,7 +654,7 @@ describe('start', () => {
'--proxy-host',
'127.0.0.1',
'--workers',
'0',
'none',
'--verbose',
],
{
Expand All @@ -678,7 +677,7 @@ describe('start', () => {
await testUtils.processExit(agentProcess2);
// Check that the password has changed
const agentProcess3 = await testUtils.pkSpawn(
['agent', 'start', '--workers', '0', '--verbose'],
['agent', 'start', '--workers', 'none', '--verbose'],
{
env: {
PK_NODE_PATH: path.join(dataDir, 'polykey'),
Expand Down Expand Up @@ -712,7 +711,7 @@ describe('start', () => {
'--proxy-host',
'127.0.0.1',
'--workers',
'0',
'none',
'--verbose',
],
{
Expand Down Expand Up @@ -763,7 +762,7 @@ describe('start', () => {
'agent',
'start',
'--workers',
'0',
'none',
'--client-host',
clientHost,
'--client-port',
Expand Down Expand Up @@ -833,7 +832,7 @@ describe('start', () => {
'agent',
'start',
'--workers',
'0',
'none',
'--verbose',
'--private-key-file',
privateKeyPath,
Expand Down Expand Up @@ -931,7 +930,7 @@ describe('start', () => {
'--proxy-host',
'127.0.0.1',
'--workers',
'0',
'none',
'--seed-nodes',
`${seedNodeId1}@${seedNodeHost1}:${seedNodePort1};<defaults>`,
'--network',
Expand Down Expand Up @@ -998,7 +997,7 @@ describe('start', () => {
'--proxy-host',
'127.0.0.1',
'--workers',
'0',
'none',
'--verbose',
],
{
Expand Down
2 changes: 1 addition & 1 deletion tests/bin/agent/status.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe('status', () => {
'--proxy-host',
'127.0.0.1',
'--workers',
'0',
'none',
'--verbose',
],
{
Expand Down
8 changes: 4 additions & 4 deletions tests/bin/agent/stop.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('stop', () => {
'--proxy-host',
'127.0.0.1',
'--workers',
'0',
'none',
],
{
env: {
Expand Down Expand Up @@ -103,7 +103,7 @@ describe('stop', () => {
'--proxy-host',
'127.0.0.1',
'--workers',
'0',
'none',
],
{
env: {
Expand Down Expand Up @@ -201,7 +201,7 @@ describe('stop', () => {
'--proxy-host',
'127.0.0.1',
'--workers',
'0',
'none',
'--verbose',
],
{
Expand Down Expand Up @@ -255,7 +255,7 @@ describe('stop', () => {
'--proxy-host',
'127.0.0.1',
'--workers',
'0',
'none',
],
{
env: {
Expand Down
14 changes: 1 addition & 13 deletions tests/bin/identities/authenticateAuthenticated.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,22 +140,10 @@ describe('authenticate/authenticated', () => {
},
));
expect(exitCode).toBe(sysexits.USAGE);
// Invalid identity
({ exitCode } = await testUtils.pkStdio(
['identities', 'authenticate', testToken.providerId, ''],
{
env: {
PK_NODE_PATH: nodePath,
PK_PASSWORD: password,
},
cwd: dataDir,
},
));
expect(exitCode).toBe(sysexits.USAGE);
// Authenticated
// Invalid provider
({ exitCode } = await testUtils.pkStdio(
['identities', 'authenticate', '--provider-id', ''],
['identities', 'authenticate', ''],
{
env: {
PK_NODE_PATH: nodePath,
Expand Down
2 changes: 1 addition & 1 deletion tests/bin/polykey.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe('polykey', () => {
'--proxy-host',
'127.0.0.1',
'--workers',
'0',
'none',
'--verbose',
'--format',
'json',
Expand Down
6 changes: 0 additions & 6 deletions tests/bin/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,6 @@ describe('bin/utils', () => {
).toBe(`${standardError.name}: ${standardError.message}\n`);
expect(binUtils.outputFormatter({ type: 'error', data: pkError })).toBe(
`${pkError.name}: ${pkError.description} - ${pkError.message}\n` +
` exitCode\t${pkError.exitCode}\n` +
` timestamp\t${timestamp.toString()}\n` +
` data\t${JSON.stringify(data)}\n`,
);
expect(
Expand All @@ -155,8 +153,6 @@ describe('bin/utils', () => {
` port\t${port}\n` +
` timestamp\t${timestamp.toString()}\n` +
` cause: ${remoteError.cause.name}: ${remoteError.cause.description} - ${remoteError.cause.message}\n` +
` exitCode\t${pkError.exitCode}\n` +
` timestamp\t${timestamp.toString()}\n` +
` data\t${JSON.stringify(data)}\n`,
);
expect(
Expand All @@ -175,8 +171,6 @@ describe('bin/utils', () => {
` port\t${port}\n` +
` timestamp\t${timestamp.toString()}\n` +
` cause: ${twoRemoteErrors.cause.cause.name}: ${twoRemoteErrors.cause.cause.description} - ${twoRemoteErrors.cause.cause.message}\n` +
` exitCode\t${pkError.exitCode}\n` +
` timestamp\t${timestamp.toString()}\n` +
` cause: ${standardError.name}: ${standardError.message}\n`,
);
// JSON
Expand Down
2 changes: 1 addition & 1 deletion tests/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ async function setupTestAgent(logger: Logger) {
'--proxy-host',
'127.0.0.1',
'--workers',
'0',
'none',
'--format',
'json',
'--verbose',
Expand Down

0 comments on commit aaaae01

Please sign in to comment.