Skip to content

Commit

Permalink
test(cli): add assertions for not containing negative summaries (#3237)
Browse files Browse the repository at this point in the history
  • Loading branch information
bernardobridge authored Jul 1, 2024
1 parent 046418f commit c3245a5
Show file tree
Hide file tree
Showing 16 changed files with 84 additions and 1 deletion.
3 changes: 3 additions & 0 deletions packages/artillery/test/cli/async-hooks-esm.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const tap = require('tap');
const { execute, generateTmpReportPath } = require('../helpers');
const { checkForNegativeValues } = require('../helpers/expectations');
const fs = require('fs');

let reportFilePath;
Expand Down Expand Up @@ -45,4 +46,6 @@ tap.test('async hooks with ESM', async (t) => {
10,
'Should have no completed VUs'
);

checkForNegativeValues(t, json);
});
7 changes: 7 additions & 0 deletions packages/artillery/test/cli/command-run.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const {
returnTmpPath,
generateTmpReportPath
} = require('../helpers');
const { checkForNegativeValues } = require('../helpers/expectations');
const fs = require('fs');
const path = require('path');
const execa = require('execa');
Expand Down Expand Up @@ -509,6 +510,10 @@ tap.test('Script using a plugin', async (t) => {
pluginCount,
'Should have same number of requests in report as plugin'
);
checkForNegativeValues(
t,
JSON.parse(fs.readFileSync(reportFilePath, 'utf8'))
);
});

tap.test(
Expand Down Expand Up @@ -723,5 +728,7 @@ tap.test("Script with 'parallel' behaves as expected", async (t) => {
expectedRequests,
`Should have made ${expectedRequests} successful requests`
);

checkForNegativeValues(t, report);
deleteFile(reportFilePath);
});
4 changes: 4 additions & 0 deletions packages/artillery/test/cli/run-typescript.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const tap = require('tap');
const { execute, generateTmpReportPath, deleteFile } = require('../helpers');
const { checkForNegativeValues } = require('../helpers/expectations');
const fs = require('fs');
const path = require('path');

Expand Down Expand Up @@ -33,6 +34,8 @@ tap.test('Can run a Typescript processor', async (t) => {
2,
'Should have emitted 2 custom metrics from ts processor'
);

checkForNegativeValues(t, json);
});

tap.test('Runs correctly when package is marked as external', async (t) => {
Expand Down Expand Up @@ -76,6 +79,7 @@ tap.test('Runs correctly when package is marked as external', async (t) => {
2,
'Should have emitted 2 custom metrics from ts processor'
);
checkForNegativeValues(t, json);

//assert that the bundle was created and marked as external
const bundleLocation = path.join(
Expand Down
3 changes: 3 additions & 0 deletions packages/artillery/test/cloud-e2e/fargate/bom.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const { test, before, beforeEach } = require('tap');
const { $ } = require('zx');
const fs = require('fs');
const { generateTmpReportPath, getTestTags } = require('../../helpers');
const { checkForNegativeValues } = require('../../helpers/expectations');

const A9_PATH = process.env.A9_PATH || 'artillery';

Expand Down Expand Up @@ -56,4 +57,6 @@ test('Run mixed-hierarchy', async (t) => {
20,
'Should have 20 "200 OK" responses'
);

checkForNegativeValues(t, report);
});
2 changes: 2 additions & 0 deletions packages/artillery/test/cloud-e2e/fargate/cw-adot.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const {
getTestTags
} = require('../../helpers');
const { getTestId, getXRayTraces } = require('./fixtures/adot/helpers.js');
const { checkForNegativeValues } = require('../../helpers/expectations');

const A9_PATH = process.env.A9_PATH || 'artillery';
// NOTE: This test reports to Artillery Dashboard to dogfood and improve visibility
Expand Down Expand Up @@ -44,6 +45,7 @@ test('traces succesfully arrive to cloudwatch', async (t) => {

const testId = getTestId(output.stdout);
const report = JSON.parse(fs.readFileSync(reportFilePath, 'utf8'));
checkForNegativeValues(t, report);

let traceMap;
try {
Expand Down
3 changes: 2 additions & 1 deletion packages/artillery/test/cloud-e2e/fargate/dd-adot.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const {
deleteFile,
getTestTags
} = require('../../helpers');

const { checkForNegativeValues } = require('../../helpers/expectations');
const { getDatadogSpans, getTestId } = require('./fixtures/adot/helpers.js');

const A9_PATH = process.env.A9_PATH || 'artillery';
Expand Down Expand Up @@ -52,6 +52,7 @@ test('traces succesfully arrive to datadog', async (t) => {

const testId = getTestId(output.stdout);
const report = JSON.parse(fs.readFileSync(reportFilePath, 'utf8'));
checkForNegativeValues(t, report);

let spanList;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const { $ } = require('zx');
const chalk = require('chalk');
const fs = require('fs');
const { generateTmpReportPath, getTestTags } = require('../../helpers');
const { checkForNegativeValues } = require('../../helpers/expectations');

const A9_PATH = process.env.A9_PATH || 'artillery';

Expand Down Expand Up @@ -39,5 +40,6 @@ test('Run uses ensure', async (t) => {
300,
'Should have 300 "200 OK" responses'
);
checkForNegativeValues(t, report);
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const { $ } = require('zx');
const chalk = require('chalk');
const fs = require('fs');
const { generateTmpReportPath, getTestTags } = require('../../helpers');
const { checkForNegativeValues } = require('../../helpers/expectations');

const A9_PATH = process.env.A9_PATH || 'artillery';

Expand Down Expand Up @@ -40,6 +41,7 @@ test('CLI should exit with non-zero exit code when there are failed expectations
10,
'Should have 10 "200 OK" responses'
);
checkForNegativeValues(t, report);
}
});

Expand Down Expand Up @@ -67,5 +69,6 @@ test('Ensure (with new interface) should still run when workers exit from expect
10,
'Should have 10 "200 OK" responses'
);
checkForNegativeValues(t, report);
}
});
2 changes: 2 additions & 0 deletions packages/artillery/test/cloud-e2e/fargate/misc.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const { $ } = require('zx');
const chalk = require('chalk');
const fs = require('fs');
const { generateTmpReportPath, getTestTags } = require('../../helpers');
const { checkForNegativeValues } = require('../../helpers/expectations');

const A9_PATH = process.env.A9_PATH || 'artillery';

Expand Down Expand Up @@ -77,6 +78,7 @@ test('Kitchen Sink Test - multiple features together', async (t) => {
40,
'Should have 40 /pony "200 OK" responses'
);
checkForNegativeValues(t, report);
});

test('Run lots-of-output', async (t) => {
Expand Down
3 changes: 3 additions & 0 deletions packages/artillery/test/cloud-e2e/fargate/processors.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const { $ } = require('zx');
const fs = require('fs');
const path = require('path');
const { generateTmpReportPath, getTestTags } = require('../../helpers');
const { checkForNegativeValues } = require('../../helpers/expectations');

const A9_PATH = process.env.A9_PATH || 'artillery';

Expand Down Expand Up @@ -36,6 +37,7 @@ test('Run with typescript processor and external package', async (t) => {
2,
'Should have emitted 2 errors'
);
checkForNegativeValues(t, report);
});

test('Run a test with an ESM processor', async (t) => {
Expand All @@ -61,4 +63,5 @@ test('Run a test with an ESM processor', async (t) => {
10,
'Should have emitted 10 custom metrics from ts processor'
);
checkForNegativeValues(t, report);
});
2 changes: 2 additions & 0 deletions packages/artillery/test/cloud-e2e/lambda/lambda-bom.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const {
generateTmpReportPath,
getImageArchitecture
} = require('../../helpers');
const { checkForNegativeValues } = require('../../helpers/expectations');

const tags = getTestTags(['type:acceptance']);

Expand Down Expand Up @@ -60,4 +61,5 @@ tap.test('Run mixed-hierarchy test in Lambda Container', async (t) => {
20,
'Should have 20 "200 OK" responses'
);
checkForNegativeValues(t, report);
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const {
generateTmpReportPath,
getImageArchitecture
} = require('../../helpers');
const { checkForNegativeValues } = require('../../helpers/expectations');

const tags = getTestTags(['type:acceptance']);
const A9_PATH = process.env.A9_PATH || 'artillery';
Expand Down Expand Up @@ -43,4 +44,5 @@ tap.test('Run dotenv test in Lambda Container', async (t) => {
50,
'Should have custom counter for env variable fruit'
);
checkForNegativeValues(t, report);
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const {
getTestTags,
getImageArchitecture
} = require('../../helpers');
const { checkForNegativeValues } = require('../../helpers/expectations');

//NOTE: all these tests report to Artillery Dashboard to dogfood and improve visibility
const tags = getTestTags(['type:acceptance']);
Expand Down Expand Up @@ -45,5 +46,6 @@ tap.test('Lambda Container run uses ensure', async (t) => {
300,
'Should have 300 "200 OK" responses'
);
checkForNegativeValues(t, report);
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const {
getTestTags,
getImageArchitecture
} = require('../../helpers');
const { checkForNegativeValues } = require('../../helpers/expectations');

const tags = getTestTags(['type:acceptance']);
let reportFilePath;
Expand Down Expand Up @@ -53,6 +54,7 @@ tap.test(
10,
'Should have 10 "200 OK" responses'
);
checkForNegativeValues(t, report);
}
}
);
2 changes: 2 additions & 0 deletions packages/artillery/test/cloud-e2e/lambda/lambda-smoke.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const {
generateTmpReportPath,
getImageArchitecture
} = require('../../helpers');
const { checkForNegativeValues } = require('../../helpers/expectations');

const tags = getTestTags(['type:acceptance']);

Expand Down Expand Up @@ -73,5 +74,6 @@ tap.test(
2,
'Should have emitted 2 errors'
);
checkForNegativeValues(t, report);
}
);
43 changes: 43 additions & 0 deletions packages/artillery/test/helpers/expectations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const _checkSummaries = (t, summaries, type) => {
for (const summaryMetric of Object.keys(summaries)) {
for (const aggregation of Object.keys(summaries[summaryMetric])) {
if (
summaries[summaryMetric][aggregation] < 0 ||
summaries[summaryMetric][aggregation] === null
) {
t.fail(
`Found invalid value in ${type} summaries: ${summaryMetric}.${aggregation} = ${summaries[summaryMetric][aggregation]}`
);
}
}
}
};

const checkForNegativeValues = (t, report) => {
const aggregateSummaries = report.aggregate?.summaries;

if (!aggregateSummaries || Object.keys(aggregateSummaries).length === 0) {
t.fail('No aggregate summaries found in the report');
}

_checkSummaries(t, aggregateSummaries, 'aggregate');

if (!report.intermediate || report.intermediate.length === 0) {
t.fail('No intermediate summaries found in the report');
}

for (const intermediate of report.intermediate) {
const intermediateSummaries = intermediate.summaries;
if (
!intermediateSummaries ||
Object.keys(intermediateSummaries).length === 0
) {
continue;
}
_checkSummaries(t, intermediateSummaries, 'intermediate');
}
};

module.exports = {
checkForNegativeValues
};

0 comments on commit c3245a5

Please sign in to comment.