Skip to content

Commit

Permalink
k6 load testing get user's products
Browse files Browse the repository at this point in the history
  • Loading branch information
hkthiet2999 committed Sep 6, 2021
1 parent 00fa913 commit db64c83
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 11 deletions.
Binary file added client/uploads/file-1630918174766.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
50 changes: 50 additions & 0 deletions server/api-load-testing/accounts-googleLogin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// import http from 'k6/http';
// import { check } from 'k6';

// export default function () {
// const google_uri = 'https://accounts.google.com/o/oauth2/v2/auth'
// const google_body = {
// 'client_secrect': 'NuGDq8U4euU-vQB-j2VtaiqS',
// 'client_id': '498160978863-vsfnulg0j0g2v4lolbtkjth0l8dk38mh.apps.googleusercontent.com'
// }
// const response_google = http.post(google_uri, google_body);
// // check(response_google, {
// // "is status 200": (r) => r.status === 200,
// // })
// const url = 'http://localhost:8080/accounts/google-login';
// const payload = JSON.stringify({
// token: 'ya29.a0ARrdaM-dgc_xV_mUQ6akxEzTaTisO-Nh5z2pMT4kUOuImFt-RLf9C0SaKJ1ZT3WPSTd3cplvoTY67AbifHM3UKYnXxsoZyfM6NMpAbzDiKdIQQ1wb0koz5drpzKYuZjbLl4_zsXsWJjJYN9yUBdvvC-DtZ6h'
// });

// const params = {
// headers: {
// 'Content-Type': 'application/json',
// },
// };

// const response = http.post(url, payload, params);

// check(response, {
// "is status 200": (r) => r.status === 200,
// "is generated token": r.json('token') !== ''
// })
// }


// export let options = {
// vus: 20,
// duration: '5s',
// };


// // export let options = {
// // stages: [
// // { duration: '5m', target: 100 }, // simulate ramp-up of traffic from 1 to 100 users over 5 minutes.
// // { duration: '10m', target: 100 }, // stay at 100 users for 10 minutes
// // { duration: '5m', target: 0 }, // ramp-down to 0 users
// // ],
// // thresholds: {
// // http_req_duration: ['p(99)<1500'], // 99% of requests must complete below 1.5s
// // 'logged in successfully': ['p(99)<1500'], // 99% of requests must complete below 1.5s
// // },
// // }
2 changes: 2 additions & 0 deletions server/api-load-testing/accounts-login.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ export default function () {
};

const response = http.post(url, payload, params);

check(response, {
"is status 200": (r) => r.status === 200,
"is generated token": r.json('token') !== ''
})
}

Expand Down
33 changes: 24 additions & 9 deletions server/api-load-testing/accounts-register.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,32 @@ export default function () {
},
};

http.post(url, payload, params);
const response = http.post(url, payload, params);

check(response, {
"is status 200": (r) => r.status === 200,
})
}


// export let options = {
// vus: 1,
// duration: '5s',
// // thresholds: {
// // 'failed requests': ['rate<0.02'],
// // http_req_duration: ['p(95)<500'],
// // http_reqs: ['count>6000']
// // },
// };

export let options = {
vus: 1,
duration: '5s',
// thresholds: {
// 'failed requests': ['rate<0.02'],
// http_req_duration: ['p(95)<500'],
// http_reqs: ['count>6000']
// },
};
stages: [
{ duration: '5m', target: 100 }, // simulate ramp-up of traffic from 1 to 100 users over 5 minutes.
{ duration: '10m', target: 100 }, // stay at 100 users for 10 minutes
{ duration: '5m', target: 0 }, // ramp-down to 0 users
],
thresholds: {
http_req_duration: ['p(99)<1500'], // 99% of requests must complete below 1.5s
'logged in successfully': ['p(99)<1500'], // 99% of requests must complete below 1.5s
},
}
4 changes: 2 additions & 2 deletions server/api-load-testing/products-getAllProduct.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ export default () => {
const loginRes = http.post(url, payload, params);

check(loginRes, {
'logged in successfully': (r) => r.json('token') !== '',
'is logged in successfully': (r) => r.json('token') !== '',
});

console.log(loginRes)
// console.log(loginRes)

let authHeaders = {
headers: {
Expand Down
53 changes: 53 additions & 0 deletions server/api-load-testing/products-getProducts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import http from 'k6/http';
import { check, group, sleep } from 'k6';

// export let options = {
// stages: [
// { duration: '5m', target: 100 }, // simulate ramp-up of traffic from 1 to 100 users over 5 minutes.
// { duration: '10m', target: 100 }, // stay at 100 users for 10 minutes
// { duration: '5m', target: 0 }, // ramp-down to 0 users
// ],
// thresholds: {
// http_req_duration: ['p(99)<1500'], // 99% of requests must complete below 1.5s
// 'logged in successfully': ['p(99)<1500'], // 99% of requests must complete below 1.5s
// },
// };

export default () => {
const url = 'http://localhost:8080/accounts/login';
const payload = JSON.stringify({
email: "testLoad@gmail.com",
password: "123456"
});

const params = {
headers: {
'Content-Type': 'application/json',
},
};

const loginRes = http.post(url, payload, params);

check(loginRes, {
'is logged in successfully': (r) => r.json('token') !== '',
});

// console.log(loginRes)

let authHeaders = {
headers: {
token: `${loginRes.json('token')}`,
},
};

let getProducts = http.get(`http://localhost:8080/products/get-product`, authHeaders).json();

check(getProducts, { 'get user Products successful': (r) => r.status === true });

sleep(1);
};

export let options = {
vus: 1,
duration: '5s',
};

0 comments on commit db64c83

Please sign in to comment.