Skip to content

Add authentication to load tests#3246

Merged
rhysyngsun merged 9 commits into
mainfrom
nl/perf-tests-auth
May 27, 2026
Merged

Add authentication to load tests#3246
rhysyngsun merged 9 commits into
mainfrom
nl/perf-tests-auth

Conversation

@rhysyngsun

@rhysyngsun rhysyngsun commented Apr 24, 2026

Copy link
Copy Markdown
Contributor

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?

  • Create a file for test user auth info in load_testing/data/ (e.g. load_testing/data/users.json) per the readme instructions.
  • Run the load tests with user auth:
    k6 run learn.smoke.ts \
      -e BACKEND_BASE_URL=https://api.learn.odl.local \
      -e FRONTEND_BASE_URL=https://learn.odl.local \
      -e USERS_JSON_FILE=data/users.json \
      -e SSO_BASE_URL=https://keycloak.odl.local \
      -e IGNORE_HTTPS_ERRORS=true \
      --console-output test.log
  • Inspect the output in test.log, you should see log statements regarding successful logins

@github-actions

github-actions Bot commented Apr 24, 2026

Copy link
Copy Markdown

OpenAPI Changes

No changes detected

View full changelog

Unexpected changes? Ensure your branch is up-to-date with main (consider rebasing).

@rhysyngsun rhysyngsun force-pushed the nl/perf-tests-auth branch 2 times, most recently from 177d412 to 193b2f8 Compare May 12, 2026 01:52
Comment thread load_testing/frontend/test.ts Fixed
Comment thread load_testing/frontend/test.ts Fixed
@rhysyngsun rhysyngsun marked this pull request as ready for review May 12, 2026 18:15
@rhysyngsun rhysyngsun force-pushed the nl/perf-tests-auth branch from d6e51c8 to 1b402dc Compare May 12, 2026 18:56
@rhysyngsun rhysyngsun changed the title Update auth setup Add authentication to load tests May 14, 2026
@mbertrand mbertrand self-assigned this May 22, 2026

@mbertrand mbertrand left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread load_testing/auth.ts Outdated
Comment thread load_testing/backend/test.ts Outdated
Comment on lines 20 to 33
@@ -18,35 +32,122 @@ async function home(page: Page) {
.click()
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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()
}

Comment thread load_testing/frontend/test.ts
Comment thread load_testing/frontend/test.ts
Comment thread load_testing/frontend/test.ts Outdated
Comment thread load_testing/learn.smoke.ts
@rhysyngsun rhysyngsun force-pushed the nl/perf-tests-auth branch from 1b402dc to 2fe13dd Compare May 22, 2026 19:52

@mbertrand mbertrand left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@rhysyngsun rhysyngsun merged commit 7975312 into main May 27, 2026
13 checks passed
@rhysyngsun rhysyngsun deleted the nl/perf-tests-auth branch May 27, 2026 13:37
@odlbot odlbot mentioned this pull request May 27, 2026
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants