Skip to content

Commit

Permalink
chore: add basic sample tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris authored and Chris committed Sep 3, 2022
0 parents commit 0afe696
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 0 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## K6 Load Testing

Grafana k6 is an open-source load testing tool that makes performance testing easy and productive for engineering teams. k6 is free, developer-centric, and extensible.

https://k6.io/docs/

### Pre-requisites

Follow the guide https://k6.io/docs/getting-started/installation/ to install K6.


### Resources

https://github.com/grafana/k6-learn

34 changes: 34 additions & 0 deletions test-k6-get-headers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import http from 'k6/http';
import { check, sleep } from 'k6';

export let options = {
vus: 1,
thresholds: {
http_req_duration: ['p(95)<=200', 'avg<=200']
}
};

export function setup() {
console.log('setup');
}

export default function () {
const params = {
cookies: { my_cookie: 'HSJSHJKSHyhJK900093233DSJSJljkl' },
headers: { 'X-MyHeader': 'k6test' },
redirects: 5,
tags: { k6test: 'yes' },
};

const res = http.get('https://httpbin.org/headers', params);

console.log(res.json()['headers']);
check(res, {
'status is 200': (r) => r.status === 200,
'X-Myheader is k6test': (r) => r.json()['headers']['X-Myheader'] == 'k6test'
})
}

export function teardown() {
console.log('teardown');
}
12 changes: 12 additions & 0 deletions test-k6-get.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import http from 'k6/http';
import { sleep } from 'k6';

export const options = {
vus: 10,
duration: '10s',
};

export default function () {
http.get('https://test.k6.io');
sleep(1);
}
20 changes: 20 additions & 0 deletions test-k6-post.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import http from 'k6/http';
import { check, sleep } from 'k6';

export let options = {
vus: 10,
iterations: 20,
thresholds: {
http_req_duration: ['p(95)<=500', 'avg<=500']
}
};

export default function() {
let url = 'https://httpbin.test.k6.io/post';
let response = http.post(url, 'Hello world!');

check(response, {
'Application says hello world!': (r) => r.body.includes('Hello world!')
});
sleep(1)
}

0 comments on commit 0afe696

Please sign in to comment.