Add authentication to load tests#3246
Conversation
OpenAPI ChangesNo changes detected Unexpected changes? Ensure your branch is up-to-date with |
91b80b7 to
57bc8f5
Compare
177d412 to
193b2f8
Compare
d6e51c8 to
1b402dc
Compare
mbertrand
left a comment
There was a problem hiding this comment.
Got it working after some tweaks described here (running in WSL in case that matters). I added two users to the JSON file, one real and one fake.
The command I ran was slightly different since I don't have all the same aliases set up:
k6 run load_testing/learn.smoke.ts \
-e BACKEND_BASE_URL=http://open.odl.local:8065 \
-e FRONTEND_BASE_URL=http://open.odl.local:8062 \
-e SSO_BASE_URL=http://kc.ol.local:8066 \
-e USERS_JSON_FILE=data/users.json \
-e IGNORE_HTTPS_ERRORS=true \
--console-output test.log| @@ -18,35 +32,122 @@ async function home(page: Page) { | |||
| .click() | |||
| } | |||
There was a problem hiding this comment.
Race condition + multi-element matcher. The data-testid mounts immediately as an empty wrapper; article children only appear after React Query resolves, so count() reads 0 and .nth(0).click() then hangs ~30s on a missing element. Also, the home page renders several ResourceCarousel instances — getByTestId matches them all; scope to first.
| async function home(page: Page, context: Context) { | |
| await page.goto(FRONTEND_BASE_URL) | |
| const carousel = page.getByTestId("resource-carousel").first() | |
| const articles = carousel.locator("article") | |
| try { | |
| await articles.first().waitFor({ timeout: 10_000 }) | |
| } catch { | |
| // carousel never populated; let the assertion below report it | |
| } | |
| const articlesCount = await articles.count() | |
| await check(carousel, { | |
| "home page carousel has 12 items": () => articlesCount === 12, | |
| }) | |
| if (articlesCount === 0) { | |
| return | |
| } | |
| await articles.nth(randomIntBetween(0, articlesCount - 1)).click() | |
| } |
1b402dc to
2fe13dd
Compare
What are the relevant tickets?
Part of https://github.com/mitodl/hq/issues/11039
Description (What does it do?)
This adds code that logs the tests in via Keycloak so they can poke around as an authenticated user.
How can this be tested?
load_testing/data/(e.g.load_testing/data/users.json) per the readme instructions.test.log, you should see log statements regarding successful logins