Skip to content

Commit 331b9f8

Browse files
tegefaulkesCMCDragonkai
authored andcommitted
fix: fixed keys renew and reset tests
It's a race condition with propagating keys changes. We needed to wait and then attempt calls with the new nodeId. I think there's a separate issue when verifying with the old nodeId. That needs to be checked inside `Polykey` though.
1 parent 7f6dbea commit 331b9f8

File tree

2 files changed

+17
-20
lines changed

2 files changed

+17
-20
lines changed

tests/keys/renew.test.ts

+8-10
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
1-
import type { NodeId } from 'polykey/dist/ids';
21
import path from 'path';
32
import fs from 'fs';
43
import Logger, { LogLevel, StreamHandler } from '@matrixai/logger';
54
import PolykeyAgent from 'polykey/dist/PolykeyAgent';
65
import * as keysUtils from 'polykey/dist/keys/utils';
76
import * as nodesUtils from 'polykey/dist/nodes/utils';
7+
import { sleep } from 'polykey/dist/utils';
88
import * as testUtils from '../utils';
99

1010
describe('renew', () => {
1111
const logger = new Logger('renew test', LogLevel.WARN, [new StreamHandler()]);
12-
const password = 'helloworld';
12+
const password = 'helloWorld';
1313
let dataDir: string;
1414
let nodePath: string;
1515
let pkAgent: PolykeyAgent;
16-
let oldNodeId: NodeId;
1716
beforeEach(async () => {
1817
dataDir = await fs.promises.mkdtemp(
1918
path.join(globalThis.tmpDir, 'polykey-test-'),
@@ -33,7 +32,6 @@ describe('renew', () => {
3332
},
3433
logger,
3534
});
36-
oldNodeId = pkAgent.keyRing.getNodeId();
3735
}, globalThis.defaultTimeout * 2);
3836
afterEach(async () => {
3937
await pkAgent.stop();
@@ -87,6 +85,10 @@ describe('renew', () => {
8785
},
8886
));
8987
expect(exitCode).toBe(0);
88+
await sleep(1000);
89+
const nodeIdEncodedNew = nodesUtils.encodeNodeId(
90+
pkAgent.keyRing.getNodeId(),
91+
);
9092
// Get new keypair and nodeId and compare against old
9193
({ exitCode, stdout } = await testUtils.pkStdio(
9294
['keys', 'keypair', '--format', 'json'],
@@ -95,9 +97,7 @@ describe('renew', () => {
9597
PK_NODE_PATH: nodePath,
9698
PK_PASSWORD: 'password-new',
9799
PK_PASSWORD_NEW: 'some-password',
98-
// Client server still using old nodeId, this should be removed if
99-
// this is fixed.
100-
PK_NODE_ID: nodesUtils.encodeNodeId(oldNodeId),
100+
PK_NODE_ID: nodeIdEncodedNew,
101101
PK_CLIENT_HOST: '127.0.0.1',
102102
PK_CLIENT_PORT: `${pkAgent.clientServicePort}`,
103103
},
@@ -113,9 +113,7 @@ describe('renew', () => {
113113
env: {
114114
PK_NODE_PATH: nodePath,
115115
PK_PASSWORD: 'password-new',
116-
// Client server still using old nodeId, this should be removed if
117-
// this is fixed.
118-
PK_NODE_ID: nodesUtils.encodeNodeId(oldNodeId),
116+
PK_NODE_ID: nodeIdEncodedNew,
119117
PK_CLIENT_HOST: '127.0.0.1',
120118
PK_CLIENT_PORT: `${pkAgent.clientServicePort}`,
121119
},

tests/keys/reset.test.ts

+9-10
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
1-
import type { NodeId } from 'polykey/dist/ids';
21
import path from 'path';
32
import fs from 'fs';
43
import Logger, { LogLevel, StreamHandler } from '@matrixai/logger';
54
import PolykeyAgent from 'polykey/dist/PolykeyAgent';
65
import * as keysUtils from 'polykey/dist/keys/utils';
76
import * as nodesUtils from 'polykey/dist/nodes/utils';
7+
import { sleep } from 'polykey/dist/utils';
88
import * as testUtils from '../utils';
99

1010
describe('reset', () => {
1111
const logger = new Logger('reset test', LogLevel.WARN, [new StreamHandler()]);
12-
const password = 'helloworld';
12+
const password = 'helloWorld';
1313
let dataDir: string;
1414
let nodePath: string;
1515
let pkAgent: PolykeyAgent;
16-
let oldNodeId: NodeId;
1716
beforeEach(async () => {
1817
dataDir = await fs.promises.mkdtemp(
1918
path.join(globalThis.tmpDir, 'polykey-test-'),
@@ -33,7 +32,6 @@ describe('reset', () => {
3332
},
3433
logger,
3534
});
36-
oldNodeId = pkAgent.keyRing.getNodeId();
3735
}, globalThis.defaultTimeout * 2);
3836
afterEach(async () => {
3937
await pkAgent.stop();
@@ -87,6 +85,11 @@ describe('reset', () => {
8785
},
8886
));
8987
expect(exitCode).toBe(0);
88+
// Wait for keys changes to propagate to the network
89+
await sleep(1000);
90+
const nodeIdEncodedNew = nodesUtils.encodeNodeId(
91+
pkAgent.keyRing.getNodeId(),
92+
);
9093
// Get new keypair and nodeId and compare against old
9194
({ exitCode, stdout } = await testUtils.pkStdio(
9295
['keys', 'keypair', '--format', 'json'],
@@ -95,9 +98,7 @@ describe('reset', () => {
9598
PK_NODE_PATH: nodePath,
9699
PK_PASSWORD: 'password-new',
97100
PK_PASSWORD_NEW: 'some-password',
98-
// Client server still using old nodeId, this should be removed if
99-
// this is fixed.
100-
PK_NODE_ID: nodesUtils.encodeNodeId(oldNodeId),
101+
PK_NODE_ID: nodeIdEncodedNew,
101102
PK_CLIENT_HOST: '127.0.0.1',
102103
PK_CLIENT_PORT: `${pkAgent.clientServicePort}`,
103104
},
@@ -113,9 +114,7 @@ describe('reset', () => {
113114
env: {
114115
PK_NODE_PATH: nodePath,
115116
PK_PASSWORD: 'password-new',
116-
// Client server still using old nodeId, this should be removed if
117-
// this is fixed.
118-
PK_NODE_ID: nodesUtils.encodeNodeId(oldNodeId),
117+
PK_NODE_ID: nodeIdEncodedNew,
119118
PK_CLIENT_HOST: '127.0.0.1',
120119
PK_CLIENT_PORT: `${pkAgent.clientServicePort}`,
121120
},

0 commit comments

Comments
 (0)