Skip to content

Commit

Permalink
test: Checks timing when needed using check
Browse files Browse the repository at this point in the history
  • Loading branch information
bprusinowski committed Feb 16, 2024
1 parent e7f93dc commit 6365d0c
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 31 deletions.
22 changes: 16 additions & 6 deletions k6/performance-tests/generate-github-actions.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ const generateAutoTests = () => {
cube,
`https://${
env === "prod" ? "" : `${env}.`
}visualize.admin.ch/api/graphql`
}visualize.admin.ch/api/graphql`,
true,
false
)
)
)
Expand Down Expand Up @@ -70,7 +72,8 @@ const generatePRTests = () => {
query,
cube,
"${{ github.event.deployment_status.target_url }}/api/graphql",
false
false,
true
)
)
)
Expand Down Expand Up @@ -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/ - </root/k6/performance-tests/graphql/${query}.js`;
} --env CUBE_LABEL=${cube.label} --env ROOT_PATH=/root/ --env CHECK_TIMING=${
checkTiming ? "true" : "false"
} - </root/k6/performance-tests/graphql/${query}.js`;
}
16 changes: 11 additions & 5 deletions k6/performance-tests/graphql/DataCubeComponents.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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 = {
Expand Down Expand Up @@ -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
);
},
}
: {}),
});
}
16 changes: 11 additions & 5 deletions k6/performance-tests/graphql/DataCubeMetadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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 = {
Expand All @@ -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
);
},
}
: {}),
});
}
16 changes: 11 additions & 5 deletions k6/performance-tests/graphql/DataCubeObservations.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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 = {
Expand All @@ -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
);
},
}
: {}),
});
}
16 changes: 11 additions & 5 deletions k6/performance-tests/graphql/DataCubePreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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 = {
Expand Down Expand Up @@ -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
);
},
}
: {}),
});
}
16 changes: 11 additions & 5 deletions k6/performance-tests/graphql/PossibleFilters.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 = {
Expand All @@ -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
);
},
}
: {}),
});
}

0 comments on commit 6365d0c

Please sign in to comment.