Skip to content

Commit 1230250

Browse files
tegefaulkesCMCDragonkai
authored andcommitted
Fixing tests/bin/sessions, removed nested describes and concurrent test
1 parent 4ca847b commit 1230250

4 files changed

Lines changed: 361 additions & 132 deletions

File tree

src/bin/utils/options.ts

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ import config from '../../config';
1717
const nodePath = new commander.Option(
1818
'-np, --node-path <path>',
1919
'Path to Node State',
20-
)
21-
.env('PK_NODE_PATH')
22-
.default(config.defaults.nodePath);
20+
).default(config.defaults.nodePath);
2321

2422
/**
2523
* Formatting choice of human, json, defaults to human
@@ -37,14 +35,6 @@ const verbose = new commander.Option('-v, --verbose', 'Log Verbose Messages')
3735
})
3836
.default(0);
3937

40-
/**
41-
* Ignore any existing state during side-effectful construction
42-
*/
43-
const fresh = new commander.Option(
44-
'--fresh',
45-
'Ignore existing state during construction',
46-
).default(false);
47-
4838
/**
4939
* Node ID used for connecting to a remote agent
5040
*/
@@ -108,16 +98,10 @@ const backgroundErrFile = new commander.Option(
10898
'Path to STDERR for agent process',
10999
);
110100

111-
const rootKeyPairBits = new commander.Option(
112-
'-rkpb --root-key-pair-bits <bitsize>',
113-
'Bit size of root key pair',
114-
).argParser(binParsers.parseNumber);
115-
116101
export {
117102
nodePath,
118103
format,
119104
verbose,
120-
fresh,
121105
nodeId,
122106
clientHost,
123107
clientPort,
@@ -128,5 +112,4 @@ export {
128112
background,
129113
backgroundOutFile,
130114
backgroundErrFile,
131-
rootKeyPairBits,
132115
};

tests/bin/agent/agent.test.ts

Lines changed: 250 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,256 @@
7575
// recursive: true,
7676
// });
7777
// });
78+
<<<<<<< HEAD
79+
=======
80+
// describe('Starting the agent in the foreground', () => {
81+
// test(
82+
// 'should start the agent and clean up the lockfile when a kill signal is received',
83+
// async () => {
84+
// const agent = testUtils.pkExec([
85+
// 'agent',
86+
// 'start',
87+
// '-np',
88+
// foregroundNodePath,
89+
// '--password-file',
90+
// passwordFile,
91+
// ]);
92+
// const status = new Status({
93+
// statusPath: statusPath(foregroundNodePath),
94+
// fs,
95+
// logger,
96+
// });
97+
// await status.waitFor('LIVE', waitForTimeout);
98+
99+
// // Kill.
100+
// await killAgent(foregroundNodePath, passwordFile);
101+
102+
// const agentResult = await agent; // Waiting for agent to finish running.
103+
// await status.waitFor('DEAD', waitForTimeout);
104+
105+
// expect(agentResult.stdout.split(' ')).toHaveLength(24);
106+
// },
107+
// global.polykeyStartupTimeout * 4,
108+
// );
109+
// test(
110+
// 'should start with port and host information as flags',
111+
// async () => {
112+
// const agent = testUtils.pkStdio([
113+
// 'agent',
114+
// 'start',
115+
// '-np',
116+
// foregroundNodePath,
117+
// '--password-file',
118+
// passwordFile,
119+
// '-ch',
120+
// '127.0.0.1',
121+
// '-cp',
122+
// '55556',
123+
// '-ih',
124+
// '127.0.0.2',
125+
// '127.0.0.3',
126+
// '-ip',
127+
// '55555',
128+
// ]);
129+
// const status = new Status({
130+
// statusPath: statusPath(foregroundNodePath),
131+
// fs,
132+
// logger,
133+
// });
134+
// const statusConfig = await status.waitFor('LIVE', waitForTimeout);
135+
// expect(statusConfig.data.clientHost).toEqual('127.0.0.1');
136+
// expect(statusConfig.data.clientPort).toEqual(55556);
137+
138+
// // Kill externally.
139+
// await killAgent(foregroundNodePath, passwordFile);
140+
// await agent; // Waiting for agent to finish running.
141+
// await status.waitFor('DEAD', waitForTimeout);
142+
// },
143+
// global.polykeyStartupTimeout * 4,
144+
// );
145+
// test(
146+
// 'should start with port and host information from env',
147+
// async () => {
148+
// const agent = testUtils.pkExec(
149+
// [
150+
// 'agent',
151+
// 'start',
152+
// '-np',
153+
// foregroundNodePath,
154+
// '--password-file',
155+
// passwordFile,
156+
// ],
157+
// {
158+
// PK_CLIENT_HOST: '127.0.0.1',
159+
// PK_CLIENT_PORT: '55556',
160+
// PK_INGRESS_HOST: '127.0.0.2',
161+
// PK_INGRESS_PORT: '55555',
162+
// },
163+
// );
164+
165+
// const status = new Status({
166+
// statusPath: statusPath(foregroundNodePath),
167+
// fs,
168+
// logger,
169+
// });
170+
// const statusConfig = await status.waitFor('LIVE', waitForTimeout);
171+
// expect(statusConfig.data.clientHost).toEqual('127.0.0.1');
172+
// expect(statusConfig.data.clientPort).toEqual(55556);
173+
174+
// // Kill externally.
175+
// await killAgent(foregroundNodePath, passwordFile);
176+
// await agent; // Waiting for agent to finish running.
177+
// await status.waitFor('DEAD', waitForTimeout);
178+
// },
179+
// global.polykeyStartupTimeout * 4,
180+
// );
181+
// test('should fail to start if an agent is already running at the path', async () => {
182+
// const result = await testUtils.pkStdio([
183+
// 'agent',
184+
// 'start',
185+
// '-np',
186+
// activeNodePath,
187+
// '--password-file',
188+
// passwordFile,
189+
// ]);
190+
// expect(result.exitCode).toBe(75);
191+
// });
192+
// });
193+
// describe('Starting the agent in the background', () => {
194+
// test(
195+
// 'should start the agent and clean up the lockfile when a kill signal is received',
196+
// async () => {
197+
// const commands = [
198+
// 'agent',
199+
// 'start',
200+
// '-b',
201+
// '-np',
202+
// backgroundNodePath,
203+
// '--password-file',
204+
// passwordFile,
205+
// ];
206+
207+
// // We can await this since it should finish after spawning the background agent.
208+
// const result = await testUtils.pkStdio(commands);
209+
// expect(result.exitCode).toBe(0);
210+
211+
// const status = new Status({
212+
// statusPath: statusPath(backgroundNodePath),
213+
// fs,
214+
// logger,
215+
// });
216+
// await status.waitFor('LIVE', waitForTimeout);
217+
218+
// // Kill it (with fire) externally.
219+
// await killAgent(backgroundNodePath, passwordFile);
220+
// await sleep(100);
221+
// await status.waitFor('DEAD', waitForTimeout);
222+
223+
// expect(result.stdout).toContain('This is your recovery code');
224+
// const code = result.stdout.split('\n')[3]; // Getting the recovery code line.
225+
// expect(code.split(' ')).toHaveLength(24);
226+
227+
// // Checking that the status was removed. FIXME
228+
// // await poll(global.polykeyStartupTimeout * 2, async () => {
229+
// // const files = await fs.promises.readdir(backgroundNodePath);
230+
// // const test = files.includes('agent-status.json');
231+
// // return !test;
232+
// // });
233+
// },
234+
// global.polykeyStartupTimeout * 5,
235+
// );
236+
// test('Should fail to start if an agent is already running at the path', async () => {
237+
// const commands = [
238+
// 'agent',
239+
// 'start',
240+
// '-b',
241+
// '-np',
242+
// activeNodePath,
243+
// '--password-file',
244+
// passwordFile,
245+
// ];
246+
// // We can await this since it should finish after spawning the background agent.
247+
// const result = await testUtils.pkStdio(commands);
248+
// expect(result.exitCode).toBe(75);
249+
// });
250+
// });
251+
// test(
252+
// 'concurrent agent start',
253+
// async () => {
254+
// const nodePath = path.join(dataDir, 'third');
255+
// const commands = [
256+
// 'agent',
257+
// 'start',
258+
// '-np',
259+
// nodePath,
260+
// '--password-file',
261+
// passwordFile,
262+
// ];
263+
264+
// // We can await this since it should finish after spawning the background agent.
265+
// const prom1 = testUtils.pkExec(commands);
266+
// const prom2 = testUtils.pkExec(commands);
267+
268+
// const status = new Status({
269+
// statusPath: statusPath(nodePath),
270+
// fs,
271+
// logger,
272+
// });
273+
// await status.waitFor('LIVE', waitForTimeout);
274+
275+
// // Kill externally.
276+
// const results = await Promise.all([prom1, prom2]); // Waiting for agent to finish running.
277+
// const resultsString = JSON.stringify(results);
278+
// expect(resultsString).toContain(':75');
279+
// expect(resultsString).toContain(':0');
280+
// },
281+
// global.defaultTimeout * 4,
282+
// );
283+
// test(
284+
// 'concurrent agent start and bootstrap.',
285+
// async () => {
286+
// const nodePath = path.join(dataDir, 'third');
287+
// const command1 = [
288+
// 'agent',
289+
// 'start',
290+
// '-np',
291+
// nodePath,
292+
// '--password-file',
293+
// passwordFile,
294+
// ];
295+
// const command2 = [
296+
// 'bootstrap',
297+
// '-np',
298+
// nodePath,
299+
// '--password-file',
300+
// passwordFile,
301+
// ];
302+
303+
// // We can await this since it should finish after spawning the background agent.
304+
// const prom1 = testUtils.pkExec(command1);
305+
// const prom2 = testUtils.pkExec(command2);
306+
307+
// const status = new Status({
308+
// statusPath: statusPath(nodePath),
309+
// fs,
310+
// logger,
311+
// });
312+
// try {
313+
// await status.waitFor('LIVE', 20000);
314+
// } catch (e) {
315+
// // Noop
316+
// }
317+
// // Kill externally.
318+
// await killAgent(nodePath, passwordFile);
319+
320+
// const results = await Promise.all([prom1, prom2]); // Waiting for agent to finish running.
321+
// expect(results[0].exitCode).toBe(0);
322+
// expect(results[1].exitCode).toBe(64);
323+
// },
324+
// global.defaultTimeout * 5,
325+
// );
326+
327+
>>>>>>> f09f815f (Fixing tests/bin/sessions, removed nested describes and concurrent test)
78328
// describe('getting agent status', () => {
79329
// test('should get the status of an online agent', async () => {
80330
// const result = await testUtils.pkStdio([

tests/bin/agent/start.test.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@ import path from 'path';
44
import fs from 'fs';
55
import readline from 'readline';
66
import Logger, { LogLevel, StreamHandler } from '@matrixai/logger';
7+
<<<<<<< HEAD
78
import { Status, errors as statusErrors } from '@/status';
89
import * as binUtils from '@/bin/utils';
910
import config from '@/config';
1011
import * as testBinUtils from '../utils';
12+
=======
13+
import * as testUtils from '../utils';
14+
>>>>>>> f09f815f (Fixing tests/bin/sessions, removed nested describes and concurrent test)
1115

1216
describe('start', () => {
1317
const logger = new Logger('start test', LogLevel.WARN, [new StreamHandler()]);
@@ -24,6 +28,7 @@ describe('start', () => {
2428
});
2529
});
2630
test(
31+
<<<<<<< HEAD
2732
'start in foreground',
2833
async () => {
2934
const password = 'abc123';
@@ -72,10 +77,14 @@ describe('start', () => {
7277
);
7378
test(
7479
'start in background',
80+
=======
81+
'start in foreground with parameters',
82+
>>>>>>> f09f815f (Fixing tests/bin/sessions, removed nested describes and concurrent test)
7583
async () => {
7684
const password = 'abc123';
7785
const passwordPath = path.join(dataDir, 'password');
7886
await fs.promises.writeFile(passwordPath, password);
87+
<<<<<<< HEAD
7988
const agentProcess = await testBinUtils.pkSpawn(
8089
[
8190
'agent',
@@ -110,6 +119,22 @@ describe('start', () => {
110119
}
111120
});
112121
});
122+
=======
123+
const agentProcess = await testUtils.pkSpawn(
124+
[
125+
'agent',
126+
'start',
127+
'--node-path',
128+
path.join(dataDir, 'polykey'),
129+
'--password-file',
130+
passwordPath,
131+
'--verbose',
132+
],
133+
undefined,
134+
dataDir,
135+
logger,
136+
);
137+
>>>>>>> f09f815f (Fixing tests/bin/sessions, removed nested describes and concurrent test)
113138
const rlOut = readline.createInterface(agentProcess.stdout!);
114139
const recoveryCode = await new Promise<RecoveryCode>(
115140
(resolve, reject) => {
@@ -122,6 +147,7 @@ describe('start', () => {
122147
recoveryCode.split(' ').length === 12 ||
123148
recoveryCode.split(' ').length === 24,
124149
).toBe(true);
150+
<<<<<<< HEAD
125151
await agentProcessExit;
126152
// Make sure that the daemon does output the recovery code
127153
// The recovery code was already written out on agentProcess
@@ -532,5 +558,19 @@ describe('start', () => {
532558
await testBinUtils.processExit(agentProcess4);
533559
},
534560
global.defaultTimeout * 3,
561+
=======
562+
agentProcess.kill('SIGTERM');
563+
const [exitCode, signal] = await new Promise<
564+
[number | null, NodeJS.Signals | null]
565+
>((resolve) => {
566+
agentProcess.once('exit', (code, signal) => {
567+
resolve([code, signal]);
568+
});
569+
});
570+
expect(exitCode).toBe(null);
571+
expect(signal).toBe('SIGTERM');
572+
},
573+
global.defaultTimeout * 4,
574+
>>>>>>> f09f815f (Fixing tests/bin/sessions, removed nested describes and concurrent test)
535575
);
536576
});

0 commit comments

Comments
 (0)