Skip to content

Commit

Permalink
fixes to jUnitIterationDuration
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelgoeke committed May 2, 2024
1 parent 7eea67f commit 6033a12
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ The included testCommon.js and testTemplate.js files include helpers and reasona
* includes an `options` block with a default of a fixed number of concurrent users (VUs) and a fixed number of iterations (per VU).
* This was a good fit for us since our workflows were long running (10+ seconds), and we try testing our infrastructure with different fixed numbers of users, and ensure the infrastructure didn't fail or slow down terribly in any spots.
* We used a fixed number of iterations (per VU) since the average times were skewed lower when iterations were forcably exited because they took beyond the grace period.
* Review the contents of testTemplate.js for more details
* includes handleSummary with custom junit reporter that provides duration and good visibility around call failures
* we consume this in Azure Pipelines with the `PublishTestResults@2` task, and pass `testResultsFiles` of `*.junit.xml`
* Review the contents of testTemplate.js for more details


`testCommon.js`
Expand All @@ -91,7 +93,7 @@ The included testCommon.js and testTemplate.js files include helpers and reasona
## Example code output

```ts
import { httpRequest, commonSetup, state } from '/testCommon.js';
import { httpRequest, commonSetup, state } from '/testCommon.js'; //hack to reference the executing folder without needing relative path

const given_vus = __ENV.AT_VU_COUNT === undefined ? 15 : __ENV.AT_VU_COUNT;
const given_iterations = __ENV.AT_ITERATIONS === undefined ? given_vus * 3 : __ENV.AT_ITERATIONS;
Expand All @@ -111,6 +113,4 @@ export default function (setup_state) {
httpRequest('GET', 'https://status.k6.io/api/v2/status.json');
httpRequest('GET', 'https://k6.io/data/jobs-positions.json');
}


```
10 changes: 5 additions & 5 deletions src/testCommon.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ export function commonSetup() {
}

export function jUnitIterationDuration(data, name) {
let avgDuration = data.metrics.iteration_duration.values.avg;
let avgDurationSeconds = data.metrics.iteration_duration.values.avg / 1000.0;
let failures = data.root_group.checks.reduce((acc, x) => acc + x.fails, 0) == 0 ? 0 : 1;
let messages = data.root_group.checks.filter(x => x.fails > 0).map(x => `${x.fails}/${data.root_group.checks.find(c => c.name === x.name.split(': ')[0]).passes} failed: ${x.name}`);
let failureMessages = data.root_group.checks.filter(x => x.fails > 0).map(x => `${x.fails}/${data.root_group.checks.find(c => c.name === x.name.split(': ')[0]).passes} failed: ${x.name}`);

return `
<testsuites id="" name="" tests="1" failures="${failures}">
<testsuite name="" tests="1" failures="${failures}" skipped="0" time="${avgDuration}" errors="0">
<testcase name="${name}" classname="${name}" time="${avgDuration}">
${messages.length === 0 ? '' : '<failure message="Some calls failed">\n' + messages.join("\n") + '\n\t\t</failure>'}
<testsuite name="" tests="1" failures="${failures}" skipped="0" time="${avgDurationSeconds}" errors="0">
<testcase name="${name}" classname="${name}" time="${avgDurationSeconds}">
${failureMessages.length === 0 ? '' : '<failure message="Calls failed. See details below.">\n' + failureMessages.join("\n") + '\n\t\t</failure>'}
</testcase>
</testsuite>
</testsuites>
Expand Down
2 changes: 1 addition & 1 deletion src/testTemplate.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { httpRequest, commonSetup, state, jUnitIterationDuration } from '/testCommon.js';
import { httpRequest, commonSetup, state, jUnitIterationDuration } from '/testCommon.js'; //hack to reference the executing folder without needing relative path
import { textSummary } from 'https://jslib.k6.io/k6-summary/0.0.2/index.js';

const given_vus = __ENV.AT_VU_COUNT === undefined ? 15 : __ENV.AT_VU_COUNT;
Expand Down

0 comments on commit 6033a12

Please sign in to comment.