Skip to content

Commit

Permalink
feat: templating the k6 file to generate it with options
Browse files Browse the repository at this point in the history
  • Loading branch information
pbastia committed Jun 17, 2021
1 parent 5db285b commit 0ec2e60
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 28 deletions.
2 changes: 1 addition & 1 deletion app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"pretest:e2e": "node cypress/support/listAuthenticatedPages.js",
"test:e2e": "cypress run",
"test:e2e-with-mocks": "cypress run --config integrationFolder=cypress/integration_mocks",
"test:smoke": "yarn build:relay-persist && pushd tests/perf; node test-guest.js; node test-admin.js; node test-reporter.js; popd",
"test:smoke": "yarn build:relay-persist && pushd tests/perf; PERF_MODE=smoke node test-guest.js; PERF_MODE=smoke node test-admin.js; PERF_MODE=smoke node test-reporter.js; popd",
"precypress": "node cypress/support/listAuthenticatedPages.js",
"cypress": "cypress open",
"cucumber:pretty": "cucumber-js --format node_modules/cucumber-pretty --format-options '{\"descriptionEnabled\":true}'",
Expand Down
8 changes: 8 additions & 0 deletions app/tests/perf/configuration/load_testing_options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default {
stages: [
{duration: '10s', target: 10},
{duration: '15s', target: 10},
{duration: '10s', target: 100},
{duration: '10s', target: 1}
]
};
4 changes: 4 additions & 0 deletions app/tests/perf/configuration/smoke_testing_options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export default {
vus: 1,
duration: '10s'
};
5 changes: 0 additions & 5 deletions app/tests/perf/k6-admin.js

This file was deleted.

5 changes: 0 additions & 5 deletions app/tests/perf/k6-guest.js

This file was deleted.

5 changes: 0 additions & 5 deletions app/tests/perf/k6-reporter.js

This file was deleted.

14 changes: 14 additions & 0 deletions app/tests/perf/k6-template.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const fs = require('fs');

module.exports.generate = function (perf_test, role, path = './k6.js') {
const fileContent = `
import executeQueries from './executeQueries.js';
export let options = require('./configuration/${perf_test}_testing_options.js').default;
export default () => {
executeQueries('${role}');
};
`;
fs.writeFileSync(path, fileContent);
};
10 changes: 6 additions & 4 deletions app/tests/perf/test-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const fs = require('fs');
const path = require('path');
const LoadTesting = require('easygraphql-load-tester');
const queries = Object.values(require('./queries.json'));
const k6Template = require('./k6-template');

const schemaCode = fs.readFileSync(
path.join(__dirname, '../../server', 'schema.graphql'),
Expand Down Expand Up @@ -52,7 +53,10 @@ const args = {

const easyGraphQLLoadTester = new LoadTesting(schemaCode, args);

easyGraphQLLoadTester.k6('k6-admin.js', {
const k6ConfigFile = `k6-guest-${process.env.PERF_MODE}.js`;
k6Template.generate(process.env.PERF_MODE, '', k6ConfigFile);

easyGraphQLLoadTester.k6(k6ConfigFile, {
customQueries: queries,
onlyCustomQueries: true,
selectedQueries: [
Expand All @@ -66,8 +70,6 @@ easyGraphQLLoadTester.k6('k6-admin.js', {
'applicationsQuery',
'organisationRequestsQuery'
],
vus: 1,
duration: '10s',
queryFile: true,
out: ['json=admin_result.json']
out: ['json=results/admin_result.json']
});
10 changes: 6 additions & 4 deletions app/tests/perf/test-guest.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const fs = require('fs');
const path = require('path');
const LoadTesting = require('easygraphql-load-tester');
const queries = Object.values(require('./queries.json'));
const k6Template = require('./k6-template');

const schemaCode = fs.readFileSync(
path.join(__dirname, '../../server', 'schema.graphql'),
Expand All @@ -15,12 +16,13 @@ const queriesWithParams = {

const easyGraphQLLoadTester = new LoadTesting(schemaCode, queriesWithParams);

easyGraphQLLoadTester.k6('k6-guest.js', {
const k6ConfigFile = `k6-guest-${process.env.PERF_MODE}.js`;
k6Template.generate(process.env.PERF_MODE, '', k6ConfigFile);

easyGraphQLLoadTester.k6(k6ConfigFile, {
customQueries: queries,
onlyCustomQueries: true,
selectedQueries: Object.keys(queriesWithParams),
vus: 1,
iterations: 1,
queryFile: true,
out: ['json=guest_result.json']
out: ['json=results/guest_result.json']
});
10 changes: 6 additions & 4 deletions app/tests/perf/test-reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const fs = require('fs');
const path = require('path');
const LoadTesting = require('easygraphql-load-tester');
const queries = Object.values(require('./queries.json'));
const k6Template = require('./k6-template');

const schemaCode = fs.readFileSync(
path.join(__dirname, '../../server', 'schema.graphql'),
Expand Down Expand Up @@ -45,12 +46,13 @@ const queriesWithParams = {

const easyGraphQLLoadTester = new LoadTesting(schemaCode, queriesWithParams);

easyGraphQLLoadTester.k6('k6-reporter.js', {
const k6ConfigFile = `k6-guest-${process.env.PERF_MODE}.js`;
k6Template.generate(process.env.PERF_MODE, '', k6ConfigFile);

easyGraphQLLoadTester.k6(k6ConfigFile, {
customQueries: queries,
onlyCustomQueries: true,
selectedQueries: Object.keys(queriesWithParams),
vus: 1,
iterations: 1,
queryFile: true,
out: ['json=reporter_result.json']
out: ['json=results/reporter_result.json']
});

0 comments on commit 0ec2e60

Please sign in to comment.