Skip to content

Commit

Permalink
Add static pages to artillery
Browse files Browse the repository at this point in the history
  • Loading branch information
acouch committed Nov 12, 2024
1 parent 02bb8d4 commit 6db3d0c
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 11 deletions.
8 changes: 7 additions & 1 deletion frontend/artillery-load-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,13 @@ scenarios:
flow:
- get:
url: "/{{ route }}"
- log: "GET /{{ route }}"
- log: "GET 404 page /{{ route }}"
- name: Static Pages
beforeScenario: getStatic
flow:
- get:
url: "/{{ route }}"
- log: "GET static page /{{ route }}"
- name: Searches
beforeScenario: getSearchQuery
flow:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
{
"ids": [
311899, 311889, 311891, 45602, 45603, 45604, 45605, 45662, 311492, 311512,
311498
],
"ids": {
"local": [
1, 2, 3, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35
],
"dev": [],
"prod": []
},
"queries": [
"test",
"grants",
Expand All @@ -11,7 +15,7 @@
"trauma",
"veterans"
],
"status": ["posted", "forecasted", "closed", "archived", "none"],
"statuses": ["posted", "forecasted", "closed", "archived", "none"],
"agencies": [
"ARPAH",
"USAID",
Expand Down Expand Up @@ -159,5 +163,6 @@
"transportation",
"affordable_care_act",
"other"
]
],
"pages": ["", "process", "research", "subscribe", "subscribe/confirmation"]
}
37 changes: 33 additions & 4 deletions frontend/tests/artillery/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import { random } from "lodash";
type dataType = {
ids: Array<number>;
queries: Array<string>;
pages: Array<string>;
status: Array<string>;
agencies: Array<string>;
funding: Array<string>;
eligibility: Array<string>;
category: Array<string>;
$environment?: string;
Expand All @@ -31,6 +33,14 @@ async function get404(context: { vars: { route: string } }) {
}
}

// eslint-disable-next-line @typescript-eslint/require-await
async function getStatic(context: {
vars: { route: string; pages: Array<string> };
}) {
context.vars.route =
context.vars.pages[random(context.vars.pages.length - 1)];
}

// eslint-disable-next-line @typescript-eslint/require-await
async function getSearchQuery(context: { vars: queryType & dataType }) {
const { queries, status, agencies, eligibility, category } = context.vars;
Expand Down Expand Up @@ -74,14 +84,32 @@ async function getSearchQuery(context: { vars: queryType & dataType }) {

async function loadData(context: { vars: dataType }) {
const env = context.vars.$environment;
const envs = new Set(["local", "dev", "stage", "prod"]);
const envs = new Set(["local", "dev", "prod"]);
if (!env || !envs.has(env)) {
throw new Error(`env ${env ?? ""} does not exist in env list`);
}
// TODO: add more env data files.
const path = "./tests/artillery/local-data.json";
const path = "./tests/artillery/params.json";
const file = await readFile(path, "utf8");
context.vars = JSON.parse(file) as dataType;
const {
ids,
pages,
queries,
agencies,
status,
eligibility,
funding,
category,
} = JSON.parse(file);
context.vars = {
ids: ids[env],
pages,
queries,
status,
agencies,
eligibility,
funding,
category,
};
}

function randomString(length: number) {
Expand All @@ -99,5 +127,6 @@ module.exports = {
loadData,
getOppId,
get404,
getStatic,
getSearchQuery,
};

0 comments on commit 6db3d0c

Please sign in to comment.