feat: k6 test
Showing
k6-test/ec-simple-test.js
0 → 100644
import {check, group, sleep} from 'k6'; | ||
import {Rate, Trend} from 'k6/metrics'; | ||
import http from 'k6/http'; | ||
export const options = { | ||
vus: 1, // 1 user looping for 10 secend | ||
scenarios: { | ||
contacts: { | ||
executor: 'constant-vus', | ||
vus: 10, | ||
duration: '1s', | ||
}, | ||
}, | ||
// scenarios: { | ||
// contacts: { | ||
// executor: 'per-vu-iterations', | ||
// vus: 2, | ||
// iterations: 1, | ||
// maxDuration: '30s', | ||
// }, | ||
// }, | ||
thresholds: { | ||
http_req_duration: ['p(99)<1500'], // 99% of requests must complete below 1.5s | ||
}, | ||
}; | ||
const URL = 'http://localhost:7168/api'; | ||
const USERNAME = 'user1'; | ||
const PASSWORD = '1234'; | ||
const PRODUCTID = '70d2d54e-1030-4a17-94b4-348713bf9631'; | ||
const TAGLIST = ["tag2"]; | ||
export default function () { | ||
let token; | ||
const loginRes = http.post(http.url`${URL}/login`, | ||
JSON.stringify({ | ||
"username": USERNAME, | ||
"password": PASSWORD | ||
})) | ||
check(loginRes, { | ||
'logged in successfully': (resp) => !!resp.body, | ||
}); | ||
const authHeaders = { | ||
headers: { | ||
Authorization: `${loginRes.body}`, | ||
'Content-Type': 'application/json' | ||
}, | ||
}; | ||
const product = http.get(http.url`${URL}/product/${PRODUCTID}`, authHeaders).json(); | ||
check(product, {'retrieved product': (obj) => !!obj}); | ||
const productByTag = http.post(http.url`${URL}/product`, JSON.stringify(TAGLIST), authHeaders).json(); | ||
check(productByTag, {'retrieved productByTag': (obj) => !!obj}); | ||
const checkout = http.post(http.url`${URL}/checkout`, JSON.stringify({ | ||
"lineItems": [ | ||
{ | ||
"sku": PRODUCTID, | ||
"quantity": 1 | ||
} | ||
], | ||
"email": "[email protected]", | ||
"creditCard": "test_card" | ||
}), authHeaders) | ||
check(checkout, {'checkout order': (obj) => !!obj}); | ||
} | ||
\ No newline at end of file |
Please register or sign in to comment