Skip to content

Commit

Permalink
Init demo KMS Techshow
Browse files Browse the repository at this point in the history
  • Loading branch information
minhhoangkms committed Oct 17, 2020
1 parent 326fb5c commit e9e5330
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 0 deletions.
14 changes: 14 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "k6-techshow",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"@types/k6": "^0.28.1"
}
}
Empty file added scenario-tests/buy-items.js
Empty file.
22 changes: 22 additions & 0 deletions services/home.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import http from 'k6/http';
import { sleep } from 'k6';

const homeService = (check, checkFailureRate) => {
// our HTTP request, note that we are saving the response to res,
// which can be accessed later

const res = http.get('http://test.k6.io');

sleep(1);

const checkRes = check(res, {
'status is 200': (r) => r.status === 200,
'response body': (r) =>
JSON.stringify(r.body).indexOf(
'Collection of simple web-pages suitable for load testing.'
) !== -1,
});
checkFailureRate.add(checkRes);
};

exports.homeService = homeService;
36 changes: 36 additions & 0 deletions unit-tests/home.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { check } from 'k6';
import { Counter, Rate } from 'k6/metrics';
import { homeService } from '../services/home.js';
import papaparse from 'https://jslib.k6.io/papaparse/5.1.1/index.js';

const data = papaparse.parse(open('../data/sample.csv'), { header: true }).data;
// A simple counter for http requests

export const requests = new Counter('http_reqs');
// Custom metric with rate value
let checkFailureRate = new Rate('check_failure_rate');
// you can specify stages of your test (ramp up/down patterns) through the options object
// target is the number of VUs you are aiming for

export const options = {
stages: [
{ target: 20, duration: '3s' },
{ target: 15, duration: '3s' },
{ target: 0, duration: '3s' },
],
thresholds: {
requests: ['count < 100'],
http_req_connecting: ['p(95)<450'],
'http_req_duration{staticAsset:yes}': ['p(95)<100'],
RTT: ['p(99)<300', 'p(70)<250', 'avg<200', 'med<150', 'min<100'],
'Content OK': ['rate>0.95'],
ContentSize: ['value<4000'],
Errors: ['count<100'],
},
};

export default function () {
console.log(__VU, JSON.stringify(data[__VU - 1]));
// our HTTP request, note that we are saving the response to res, which can be accessed later
homeService(check, checkFailureRate);
}

0 comments on commit e9e5330

Please sign in to comment.