Skip to content

Commit

Permalink
Set up test n8n dir
Browse files Browse the repository at this point in the history
  • Loading branch information
ivov committed Apr 11, 2024
1 parent 7e35897 commit 4414eee
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 3 deletions.
32 changes: 32 additions & 0 deletions packages/cli/test/benchmarks/init.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,38 @@
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { mkdirSync, mkdtempSync, writeFileSync } from 'node:fs';

import { Config } from '@oclif/core';
import { Start } from '@/commands/start';
import * as testDb from '../integration/shared/testDb';
import Container from 'typedi';
import { InstanceSettings } from 'n8n-core';

/** Set up a temp `.n8n` dir for benchmarks to use. */
function n8nDir() {
const baseDir = join(tmpdir(), 'n8n-benchmarks/');

mkdirSync(baseDir, { recursive: true });

const subDir = mkdtempSync(baseDir);
const n8nDir = join(subDir, '.n8n');

mkdirSync(n8nDir);

writeFileSync(
join(n8nDir, 'config'),
JSON.stringify({ encryptionKey: 'temp_encryption_key', instanceId: '123' }),
'utf-8',
);

const instanceSettings = Container.get(InstanceSettings);
instanceSettings.n8nFolder = n8nDir;
Container.set(InstanceSettings, instanceSettings);

console.log('n8nDir', n8nDir);
}

/** Initialize an n8n main process for benchmarking. */
async function mainProcess() {
const args: string[] = [];
const _config = new Config({ root: __dirname });
Expand All @@ -13,6 +44,7 @@ async function mainProcess() {
}

export const init = {
n8nDir,
database: testDb.init,
mainProcess,
};
2 changes: 2 additions & 0 deletions packages/cli/test/benchmarks/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ async function main() {
const _bench = new Bench({ time: 0, iterations: 1 }); // @TEMP: Remove arg
const bench = withCodSpeed(_bench);

process.env.NODE_ENV = 'test';

register(bench);

// await bench.warmup(); // @TODO: Restore
Expand Down
5 changes: 3 additions & 2 deletions packages/cli/test/benchmarks/webhook.benchmark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ export function webhook(bench: Bench) {
beforeAll: async () => {
console.log('beforeAll start');

await init.database();
init.n8nDir();
await init.database(); // @TODO: Test with Postgres
await init.mainProcess();

console.log('beforeAll end');
},
afterAll: () => {
// stop process // @TODO
// @TODO stop main process gracefully
},
},
);
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/InstanceSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class InstanceSettings {
private readonly userHome = this.getUserHome();

/** The path to the n8n folder in which all n8n related data gets saved */
readonly n8nFolder = path.join(this.userHome, '.n8n');
n8nFolder = path.join(this.userHome, '.n8n');

/** The path to the folder where all generated static assets are copied to */
readonly staticCacheDir = path.join(this.userHome, '.cache/n8n/public');
Expand Down

0 comments on commit 4414eee

Please sign in to comment.