Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to pass the concurrent id to the file under test #90

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ This will run the specified puppeteer script once in chrome headless instance.
`--c` flag is to mention number of concurrent executions per sample
`--silent` boolean to enable or disable logs
`--outputFile` send performance results to output file
`--addId` flag is to add a unique number as first argument to the puppeteer script

$ puppeteer-loadtest --s=100 --c=25 --file=sample.js

Expand All @@ -39,6 +40,8 @@ This will run a total of 100 runs through the specified puppeteer script across
$ puppeteer-loadtest --file=./test/sample.js --s=100 --c=25

$ puppeteer-loadtest --file=./test/sample.js --s=100 --c=25 --silent=true

$ puppeteer-loadtest --file=./test/sample.js --s=100 --c=25 --addId

$ puppeteer-loadtest --file=./test/sample.js -s 100 -c 25

Expand Down
4 changes: 3 additions & 1 deletion bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const file = argv.file;
const samplesRequested = argv.s || 1;
const concurrencyRequested = argv.c || 1;
const silent = argv.silent || false;
const addIdArgument = argv.addId || false;
const outputFile = argv.outputFile;

if (!file) {
Expand All @@ -39,8 +40,9 @@ const start = async () => {
file,
samplesRequested,
concurrencyRequested,
addIdArgument
});

if (results) {
if (outputFile) {
fs.writeFileSync(outputFile, JSON.stringify(results, null, "\t"));
Expand Down
14 changes: 8 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const defaultOptions = {
concurrencyRequested: 1,
results: {},
samplesCount: 0,
addIdArgument: false
}

debug('puppeteer-loadtest is loading...');
Expand Down Expand Up @@ -47,21 +48,22 @@ const executeTheCommand = function({ cmd, concurrencyCount, samplesCount, result
if(error) reject(error);
resolve(stdout);
});
});
});
};

const doAnotherSample = async (options) => {
const doAnotherSample = async (options) => {
let {
concurrencyRequested,
file,
samplesCount,
samplesRequested,
results,
addIdArgument
} = options;

if(samplesCount < samplesRequested) {
startSampleLogPerformance(results, samplesCount);
await doConcurrency({ results, samplesCount, concurrencyRequested, file });
await doConcurrency({ results, samplesCount, concurrencyRequested, file, addIdArgument });
stopSampleLogPerformance(results, samplesCount);
samplesCount += 1;
return doAnotherSample({
Expand All @@ -76,13 +78,13 @@ const doAnotherSample = async (options) => {
return results;
};

const doConcurrency = async ({ results, samplesCount, concurrencyRequested, file}) => {
const doConcurrency = async ({ results, samplesCount, concurrencyRequested, file, addIdArgument}) => {
const promisesArray = [];

for(let i=0; i < concurrencyRequested; i += 1) {
promisesArray.push(
executeTheCommand({
cmd: `node ${file}`,
executeTheCommand({
cmd: addIdArgument ? `node ${file} ${i}` : `node ${file}`,
concurrencyCount: i,
results,
samplesCount,
Expand Down
Loading