From 6033a12acc4030844e91f17bcb2c9f043dbf55b6 Mon Sep 17 00:00:00 2001 From: Michael Goeke Date: Thu, 2 May 2024 14:24:48 -0700 Subject: [PATCH] fixes to jUnitIterationDuration --- README.md | 8 ++++---- src/testCommon.js | 10 +++++----- src/testTemplate.js | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index e80bef0..ba5f387 100644 --- a/README.md +++ b/README.md @@ -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` @@ -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; @@ -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'); } - - ``` \ No newline at end of file diff --git a/src/testCommon.js b/src/testCommon.js index 0b7a5c5..a4ca45f 100644 --- a/src/testCommon.js +++ b/src/testCommon.js @@ -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 ` - - - ${messages.length === 0 ? '' : '\n' + messages.join("\n") + '\n\t\t'} + + + ${failureMessages.length === 0 ? '' : '\n' + failureMessages.join("\n") + '\n\t\t'} diff --git a/src/testTemplate.js b/src/testTemplate.js index 4511f25..c99bd04 100644 --- a/src/testTemplate.js +++ b/src/testTemplate.js @@ -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;