diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 11a820d7..50f6623e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -74,4 +74,5 @@ repos: .pre-commit-config.yaml| ^src/core/engines/webjs/session.webjs.core.ts| ^src/core/engines/webjs/_lodash.js| + ^tests/perf/.*| )$ diff --git a/package.json b/package.json index c417278c..e8de4e19 100644 --- a/package.json +++ b/package.json @@ -120,7 +120,8 @@ "ts-loader": "^6.2.1", "ts-node": "^10.9.1", "tsconfig-paths": "^4.1.0", - "typescript": "^4.8.4" + "typescript": "^4.8.4", + "yargs": "^17.7.2" }, "jest": { "moduleFileExtensions": [ diff --git a/tests/perf/start.js b/tests/perf/start.js new file mode 100644 index 00000000..35366203 --- /dev/null +++ b/tests/perf/start.js @@ -0,0 +1,56 @@ +// eslint-disable-next-line @typescript-eslint/no-var-requires +const axios = require('axios'); +// eslint-disable-next-line @typescript-eslint/no-var-requires +const yargs = require('yargs/yargs'); +// eslint-disable-next-line @typescript-eslint/no-var-requires +const { hideBin } = require('yargs/helpers'); + +// Parse CLI arguments +const argv = yargs(hideBin(process.argv)) + .option('sessions', { + alias: 'n', + type: 'number', + description: 'Number of sessions to create', + default: 10, + }) + .option('api-key', { + alias: 'k', + type: 'string', + description: 'API key for authentication', + demandOption: true, + }) + .help().argv; + +const createSessions = async (numSessions, apiKey) => { + const url = 'http://localhost:3000/api/sessions/'; + + for (let i = 1; i <= numSessions; i++) { + try { + console.log(`Creating session ${i}`); + const response = await axios.post( + url, + { + name: '', + config: { + metadata: {}, + webhooks: [], + }, + start: true, + }, + { + headers: { + Accept: 'application/json', + 'X-Api-Key': apiKey, + 'Content-Type': 'application/json', + }, + }, + ); + console.log(`Session ${i} created successfully:`, response.data); + } catch (error) { + console.error(`Error creating session ${i}:`, error.message); + } + } +}; + +// Run the script +createSessions(argv.sessions, argv['api-key']); diff --git a/yarn.lock b/yarn.lock index 229282a2..172ff59b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -12646,6 +12646,7 @@ __metadata: ulid: ^2.3.0 whatsapp-web.js: "github:devlikeapro/whatsapp-web.js#fork-main-channels" write-file-atomic: ^6.0.0 + yargs: ^17.7.2 dependenciesMeta: bufferutil: optional: true