From 6365d0c634efb8287bc4cafbb9b643467f7a0458 Mon Sep 17 00:00:00 2001 From: Bartosz Prusinowski Date: Fri, 16 Feb 2024 10:29:53 +0100 Subject: [PATCH] test: Checks timing when needed using `check` --- .../generate-github-actions.mjs | 22 ++++++++++++++----- .../graphql/DataCubeComponents.js | 16 +++++++++----- .../graphql/DataCubeMetadata.js | 16 +++++++++----- .../graphql/DataCubeObservations.js | 16 +++++++++----- .../graphql/DataCubePreview.js | 16 +++++++++----- .../graphql/PossibleFilters.js | 16 +++++++++----- 6 files changed, 71 insertions(+), 31 deletions(-) diff --git a/k6/performance-tests/generate-github-actions.mjs b/k6/performance-tests/generate-github-actions.mjs index 2f2f9b4fe..90eb9aa3f 100644 --- a/k6/performance-tests/generate-github-actions.mjs +++ b/k6/performance-tests/generate-github-actions.mjs @@ -22,7 +22,9 @@ const generateAutoTests = () => { cube, `https://${ env === "prod" ? "" : `${env}.` - }visualize.admin.ch/api/graphql` + }visualize.admin.ch/api/graphql`, + true, + false ) ) ) @@ -70,7 +72,8 @@ const generatePRTests = () => { query, cube, "${{ github.event.deployment_status.target_url }}/api/graphql", - false + false, + true ) ) ) @@ -104,12 +107,19 @@ jobs: generatePRTests(); -function getRunCommand(env, query, cube, endpoint, sendToPrometheus = true) { +function getRunCommand( + env, + query, + cube, + endpoint, + sendToPrometheus = true, + checkTiming = true +) { return `k6 run${ sendToPrometheus ? " -o experimental-prometheus-rw" : "" } --tag testid=${query} --env ENV=${env} --env ENDPOINT=${endpoint} --env CUBE_IRI=${ cube.iri - } --env CUBE_LABEL=${ - cube.label - } --env ROOT_PATH=/root/ - cube.iri === cubeIri); +const checkTiming = __ENV.CHECK_TIMING === "true"; const variables = { locale: "en", @@ -37,11 +38,6 @@ const variables = { /** @type {import("k6/options").Options} */ export const options = { iterations: 2, - thresholds: { - http_req_duration: [ - `avg<${2 * metadata.queries.DataCubeComponents.expectedDuration}`, - ], - }, }; const headers = { @@ -69,5 +65,15 @@ export default function Components() { body.data.dataCubeComponents.measures.length > 0 ); }, + ...(checkTiming + ? { + "Response time must be fast": (res) => { + return ( + res.timings.duration < + 2 * metadata.queries.DataCubeComponents.expectedDuration + ); + }, + } + : {}), }); } diff --git a/k6/performance-tests/graphql/DataCubeMetadata.js b/k6/performance-tests/graphql/DataCubeMetadata.js index ddeb17534..749500f12 100644 --- a/k6/performance-tests/graphql/DataCubeMetadata.js +++ b/k6/performance-tests/graphql/DataCubeMetadata.js @@ -24,6 +24,7 @@ const cubeIri = __ENV.CUBE_IRI; const cubeLabel = __ENV.CUBE_LABEL; const endpoint = __ENV.ENDPOINT; const metadata = cubes.find((cube) => cube.iri === cubeIri); +const checkTiming = __ENV.CHECK_TIMING === "true"; const variables = { locale: "en", @@ -37,11 +38,6 @@ const variables = { /** @type {import("k6/options").Options} */ export const options = { iterations: 2, - thresholds: { - http_req_duration: [ - `avg<${2 * metadata.queries.DataCubeMetadata.expectedDuration}`, - ], - }, }; const headers = { @@ -66,5 +62,15 @@ export default function Components() { body.data.dataCubeMetadata.iri === cubeIri ); }, + ...(checkTiming + ? { + "Response time must be fast": (res) => { + return ( + res.timings.duration < + 2 * metadata.queries.DataCubeMetadata.expectedDuration + ); + }, + } + : {}), }); } diff --git a/k6/performance-tests/graphql/DataCubeObservations.js b/k6/performance-tests/graphql/DataCubeObservations.js index e76726568..e6bed7f73 100644 --- a/k6/performance-tests/graphql/DataCubeObservations.js +++ b/k6/performance-tests/graphql/DataCubeObservations.js @@ -24,6 +24,7 @@ const cubeIri = __ENV.CUBE_IRI; const cubeLabel = __ENV.CUBE_LABEL; const endpoint = __ENV.ENDPOINT; const metadata = cubes.find((cube) => cube.iri === cubeIri); +const checkTiming = __ENV.CHECK_TIMING === "true"; const variables = { locale: "en", @@ -38,11 +39,6 @@ const variables = { /** @type {import("k6/options").Options} */ export const options = { iterations: 2, - thresholds: { - http_req_duration: [ - `avg<${2 * metadata.queries.DataCubeObservations.expectedDuration}`, - ], - }, }; const headers = { @@ -69,5 +65,15 @@ export default function Observations() { body.data.dataCubeObservations.sparqlEditorUrl ); }, + ...(checkTiming + ? { + "Response time must be fast": (res) => { + return ( + res.timings.duration < + 2 * metadata.queries.DataCubeObservations.expectedDuration + ); + }, + } + : {}), }); } diff --git a/k6/performance-tests/graphql/DataCubePreview.js b/k6/performance-tests/graphql/DataCubePreview.js index 396fefe87..ea26f0573 100644 --- a/k6/performance-tests/graphql/DataCubePreview.js +++ b/k6/performance-tests/graphql/DataCubePreview.js @@ -24,6 +24,7 @@ const cubeIri = __ENV.CUBE_IRI; const cubeLabel = __ENV.CUBE_LABEL; const endpoint = __ENV.ENDPOINT; const metadata = cubes.find((cube) => cube.iri === cubeIri); +const checkTiming = __ENV.CHECK_TIMING === "true"; const variables = { locale: "en", @@ -38,11 +39,6 @@ const variables = { /** @type {import("k6/options").Options} */ export const options = { iterations: 2, - thresholds: { - http_req_duration: [ - `avg<${2 * metadata.queries.DataCubePreview.expectedDuration}`, - ], - }, }; const headers = { @@ -72,5 +68,15 @@ export default function Components() { body.data.dataCubePreview.observations.length > 0 ); }, + ...(checkTiming + ? { + "Response time must be fast": (res) => { + return ( + res.timings.duration < + 2 * metadata.queries.DataCubePreview.expectedDuration + ); + }, + } + : {}), }); } diff --git a/k6/performance-tests/graphql/PossibleFilters.js b/k6/performance-tests/graphql/PossibleFilters.js index 58bc5241a..9142e8eae 100644 --- a/k6/performance-tests/graphql/PossibleFilters.js +++ b/k6/performance-tests/graphql/PossibleFilters.js @@ -28,6 +28,7 @@ const cubeIri = __ENV.CUBE_IRI; const cubeLabel = __ENV.CUBE_LABEL; const endpoint = __ENV.ENDPOINT; const metadata = cubes.find((cube) => cube.iri === cubeIri); +const checkTiming = __ENV.CHECK_TIMING === "true"; const variables = { iri: cubeIri, @@ -40,11 +41,6 @@ const variables = { /** @type {import("k6/options").Options} */ export const options = { iterations: 2, - thresholds: { - http_req_duration: [ - `avg<${2 * metadata.queries.PossibleFilters.expectedDuration}`, - ], - }, }; const headers = { @@ -69,5 +65,15 @@ export default function Observations() { body.data.possibleFilters.length > 0 ); }, + ...(checkTiming + ? { + "Response time must be fast": (res) => { + return ( + res.timings.duration < + 2 * metadata.queries.PossibleFilters.expectedDuration + ); + }, + } + : {}), }); }