Make hostname optional
This commit is contained in:
parent
2f551f4d4a
commit
72f0bcd3a8
6 changed files with 39 additions and 16 deletions
33
README.md
33
README.md
|
@ -1,37 +1,48 @@
|
|||
# performance-testing
|
||||
The code from my YouTube video on "How to do Performance Testing with k6"
|
||||
|
||||
You first need to run the API:
|
||||
You first need to run the API which you can do in 2 ways.
|
||||
|
||||
Using dotnet:
|
||||
```sh
|
||||
cd src
|
||||
dotnet run
|
||||
```
|
||||
|
||||
Using Docker:
|
||||
```sh
|
||||
docker-compose up
|
||||
```
|
||||
|
||||
Then in a seperate terminal window run the tests using the commands below.
|
||||
|
||||
I have added a HOSTNAME variable to each of the scripts which needs to be added when running them.
|
||||
Note if you want to run these scripts against an API hosted on another machine you can use the HOSTNAME environment variable. e.g.
|
||||
|
||||
```sh
|
||||
k6 run -e HOSTNAME=192.168.1.1:5157 tests/simple-test.js
|
||||
```
|
||||
|
||||
## Simple Test
|
||||
```sh
|
||||
k6 run -e HOSTNAME=localhost:5157 tests/simple-test.js
|
||||
k6 run tests/simple-test.js
|
||||
```
|
||||
|
||||
## Stress Test
|
||||
```sh
|
||||
k6 run -e HOSTNAME=localhost:5157 tests/stress-test.js
|
||||
```
|
||||
|
||||
## Spike Test
|
||||
```sh
|
||||
k6 run -e HOSTNAME=localhost:5157 tests/spike-test.js
|
||||
k6 run tests/stress-test.js
|
||||
```
|
||||
|
||||
## Load Test
|
||||
```sh
|
||||
k6 run -e HOSTNAME=localhost:5157 tests/load-test.js
|
||||
k6 run tests/load-test.js
|
||||
```
|
||||
|
||||
## Spike Test
|
||||
```sh
|
||||
k6 run tests/spike-test.js
|
||||
```
|
||||
|
||||
## Soak Test
|
||||
```sh
|
||||
k6 run -e HOSTNAME=localhost:5157 tests/soak-test.js
|
||||
k6 run tests/soak-test.js
|
||||
```
|
|
@ -2,6 +2,8 @@ import http from 'k6/http';
|
|||
import { sleep } from 'k6';
|
||||
import { SharedArray } from 'k6/data';
|
||||
|
||||
if (hostname == null) hostname = 'localhost:5157';
|
||||
|
||||
export const options = {
|
||||
stages: [
|
||||
{ duration: '5m', target: 200 }, // ramp up
|
||||
|
@ -30,6 +32,6 @@ const dates = new SharedArray('dates', function () {
|
|||
|
||||
export default () => {
|
||||
const randomDate = dates[Math.floor(Math.random() * dates.length)];
|
||||
http.get(`http://${__ENV.HOSTNAME}/age/${randomDate}`);
|
||||
http.get(`http://${hostname}/age/${randomDate}`);
|
||||
sleep(1);
|
||||
};
|
|
@ -1,10 +1,14 @@
|
|||
import http from 'k6/http';
|
||||
|
||||
var hostname = __ENV.HOSTNAME;
|
||||
|
||||
if (hostname == null) hostname = 'localhost:5157';
|
||||
|
||||
export const options = {
|
||||
vus: 1,
|
||||
duration: '10s'
|
||||
};
|
||||
|
||||
export default () => {
|
||||
http.get(`http://${__ENV.HOSTNAME}/age/1987-09-01`);
|
||||
http.get(`http://${hostname}/age/1987-09-01`);
|
||||
};
|
|
@ -2,6 +2,8 @@ import http from 'k6/http';
|
|||
import { sleep } from 'k6';
|
||||
import { SharedArray } from 'k6/data';
|
||||
|
||||
if (hostname == null) hostname = 'localhost:5157';
|
||||
|
||||
export const options = {
|
||||
stages: [
|
||||
{ duration: '5m', target: 200 }, // ramp up
|
||||
|
@ -27,6 +29,6 @@ const dates = new SharedArray('dates', function () {
|
|||
|
||||
export default () => {
|
||||
const randomDate = dates[Math.floor(Math.random() * dates.length)];
|
||||
http.get(`http://${__ENV.HOSTNAME}/age/${randomDate}`);
|
||||
http.get(`http://${hostname}/age/${randomDate}`);
|
||||
sleep(1);
|
||||
};
|
|
@ -2,6 +2,8 @@ import http from 'k6/http';
|
|||
import { sleep } from 'k6';
|
||||
import { SharedArray } from 'k6/data';
|
||||
|
||||
if (hostname == null) hostname = 'localhost:5157';
|
||||
|
||||
export const options = {
|
||||
stages: [
|
||||
{ duration: '10s', target: 200 }, // ramp up
|
||||
|
@ -31,6 +33,6 @@ const dates = new SharedArray('dates', function () {
|
|||
|
||||
export default () => {
|
||||
const randomDate = dates[Math.floor(Math.random() * dates.length)];
|
||||
http.get(`http://${__ENV.HOSTNAME}/age/${randomDate}`);
|
||||
http.get(`http://${hostname}/age/${randomDate}`);
|
||||
sleep(1);
|
||||
};
|
|
@ -2,6 +2,8 @@ import http from 'k6/http';
|
|||
import { sleep } from 'k6';
|
||||
import { SharedArray } from 'k6/data';
|
||||
|
||||
if (hostname == null) hostname = 'localhost:5157';
|
||||
|
||||
export const options = {
|
||||
stages: [
|
||||
{ duration: '1m', target: 200 }, // ramp up
|
||||
|
@ -31,6 +33,6 @@ const dates = new SharedArray('dates', function () {
|
|||
|
||||
export default () => {
|
||||
const randomDate = dates[Math.floor(Math.random() * dates.length)];
|
||||
http.get(`http://${__ENV.HOSTNAME}/age/${randomDate}`);
|
||||
http.get(`http://${hostname}/age/${randomDate}`);
|
||||
sleep(1);
|
||||
};
|
Loading…
Reference in a new issue