-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add basic load test utilities to the application.
- Loading branch information
1 parent
0b1d4ad
commit ea0f886
Showing
5 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Load Tests | ||
|
||
This utilizes [k6](https://github.com/grafana/k6) to test our application | ||
under a defined amount of load. You can | ||
[install k6 here](https://grafana.com/docs/k6/latest/get-started/installation/). | ||
|
||
These tests aren't promised to work out of the box. You may need | ||
to tweak things future-djangonaut. | ||
|
||
To run a test: | ||
|
||
```shell | ||
k6 run test_blog.js | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import http from "k6/http"; | ||
import { check, sleep } from "k6"; | ||
|
||
// Test configuration | ||
export const options = { | ||
thresholds: { | ||
// Assert that 99% of requests finish within 3000ms. | ||
http_req_duration: ["p(99) < 3000"], | ||
}, | ||
// Ramp the number of virtual users up and down | ||
stages: [ | ||
{ duration: "30s", target: 15 }, | ||
{ duration: "1m", target: 15 }, | ||
{ duration: "20s", target: 0 }, | ||
], | ||
}; | ||
|
||
// Simulated user behavior | ||
export function basicPlan(url) { | ||
return function () { | ||
let res = http.get(url); | ||
// Validate response status | ||
check(res, { "status was 200": (r) => r.status == 200 }); | ||
sleep(1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import {options, basicPlan} from "./basic_plan.js"; | ||
|
||
exports.options = options | ||
|
||
const testBlog = basicPlan("https://djangonaut.space/comms/2024/03/08/2024-session-1-mission-debrief/") | ||
|
||
// Simulated user behavior | ||
export default testBlog |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import {options, basicPlan} from "./basic_plan.js"; | ||
|
||
exports.options = options | ||
|
||
const testSession = basicPlan("https://djangonaut.space/sessions/2024-session-2/") | ||
|
||
// Simulated user behavior | ||
export default testSession |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import http from "k6/http"; | ||
import { check, sleep } from "k6"; | ||
import {options} from "./basic_plan.js"; | ||
|
||
// Test configuration | ||
exports.options = options | ||
|
||
const PASSWORD = ''; // Reset the password on production | ||
|
||
// Simulated user behavior | ||
export default function () { | ||
let res = http.get("https://djangonaut.space/accounts/login/"); | ||
check(res, { "status was 200": (r) => r.status == 200 }); | ||
res = res.submitForm({ | ||
formSelector: 'form', | ||
fields: { username: `load_test${__ITER}`, password: PASSWORD }, | ||
}); | ||
check(res, { "status was 200": (r) => r.status == 200 }); | ||
res = http.get("https://djangonaut.space/survey_response/create/load-test/"); | ||
check(res, { "status was 200": (r) => r.status == 200 }); | ||
res = res.submitForm({ | ||
formSelector: 'form', | ||
fields: { field_survey_1: 'load_test', field_survey_2: 2, field_survey_3: "final value over 100 characters. final value over 100 characters. final value over 100 characters. final value over 100 characters. final value over 100 characters. final value over 100 characters. final value over 100 characters. final value over 100 characters. final value over 100 characters. final value over 100 characters. " }, | ||
}); | ||
check(res, { "status was 200": (r) => r.status == 200 }); | ||
sleep(1); | ||
} |