Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ frontends/.yarn

.yarn/*
!.yarn/releases
load_testing/.yarn/*
!load_testing/.yarn/releases

# Typescript
tsconfig.tsbuildinfo
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ repos:
language: node
types_or: [javascript, jsx, ts, tsx]
args: []
exclude: "(node_modules/|.yarn/)"
exclude: "(node_modules/|.yarn/|load_testing/)"
require_serial: false
additional_dependencies:
- eslint@8
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ services:
ports:
- "8089:8089"
volumes:
- ./load_testing:/mnt/locust
- ./load_testing_locust:/mnt/locust
command: -f /mnt/locust/locustfile.py --master -H http://nginx:8063 --class-picker
links:
- nginx
Expand All @@ -86,7 +86,7 @@ services:
locust-worker:
image: locustio/locust
volumes:
- ./load_testing:/mnt/locust
- ./load_testing_locust:/mnt/locust
command: -f /mnt/locust/locustfile.py --worker --master-host locust
links:
- nginx
Expand Down
11 changes: 11 additions & 0 deletions load_testing/.stylelintrc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
extends:
- stylelint-config-standard
rules:
selector-class-pattern:
- (^ck.*)|((^Mui[A-Z-])|^([a-z][a-z0-9]*)((-|__?)[a-z0-9]+)*$) # CKEditor, MUI or kebab-case
- message: "Expected class selector to be kebab-case"
overrides:
- files:
- "**/*.tsx"
- "**/*.ts"
customSyntax: postcss-styled-syntax
21 changes: 11 additions & 10 deletions load_testing/README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
## Load Testing
## k6 load testing

#### Locust
### Usage (Docker)

The load testing system uses [Locust](https://docs.locust.io/en/stable/index.html) to run the load tests against the APIs. The entrypoint for this is `locustfile.py`. Locust automatically picks up the testing configuration based on subclassing things, you can read the docs for further details.
```shell
./scripts/k6.sh -e BACKEND_BASE_URL=#### -e FRONTEND_BASE_URL=####
```

#### Running
### Usage (local k6)

- Add `load-testing` to your `COMPOSE_PROFILES` setting.
- Run `docker compose up` or `docker compose up locust locust-worker` (a more minimal set of services)
- Go to http://localhost:8089/ and you should see the web UI for Locust.
- Set the options you want to test (100 users is reasonable for local tests) and click Start
- If you're testing against a backend that isn't reachable through the `nginx` hostname, you'll need to specify the alternative hostname.
- You can use this to test against deployed environments.
- Install [k6](https://grafana.com/docs/k6/latest/set-up/install-k6/)

```shell
k6 run learn.ts -e BACKEND_BASE_URL=#### -e FRONTEND_BASE_URL=####
```
Empty file removed load_testing/__init__.py
Empty file.
13 changes: 13 additions & 0 deletions load_testing/auth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { SharedArray } from "k6/data"

export function getAccessToken(): String {
return __ENV.AUTH_ACCESS_TOKEN
}

export const users = new SharedArray("users", function () {
if (!__ENV.USERS_JSON_FILE) {
return []
}

return JSON.parse(open(__ENV.USERS_JSON_FILE))
})
28 changes: 28 additions & 0 deletions load_testing/backend/client/client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Params } from "k6/http"
import { BACKEND_BASE_URL } from "../../config.ts"
import { MITLearnAPIClient as V0Client } from "./v0/api.ts"
import { MITLearnAPIClient as V1Client } from "./v1/api.ts"
import { getAccessToken } from "../../auth.ts"

function getCommonRequestParameters(): Params {
const accessToken = getAccessToken()

return {
headers: {
...(!!accessToken ? { Authorization: `Bearer ${accessToken}` } : {}),
},
}
}

export function createV0Client(): V0Client {
return new V0Client({
baseUrl: BACKEND_BASE_URL,
commonRequestParameters: getCommonRequestParameters(),
})
}
export function createV1Client(): V1Client {
return new V1Client({
baseUrl: BACKEND_BASE_URL,
commonRequestParameters: getCommonRequestParameters(),
})
}
Loading
Loading