-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrunTests.js
50 lines (46 loc) · 1.7 KB
/
runTests.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import example1Tests from './tests/example1.js'
import example2Tests from './tests/example2.js'
import { Httpx } from 'https://jslib.k6.io/httpx/0.0.3/index.js';
const session = new Httpx({
baseURL: __ENV.BASE_URL,
headers: {
accept: 'application/json, text/javascript, */*; q=0.01',
'Accept-Encoding': 'gzip, deflate, br',
'Content-Type': 'application/json',
},
timeout: 20000, // 20s timeout.
});
if (__ENV.AUTH_TOKEN) {
session.addHeader('Authorization', `Bearer ${__ENV.AUTH_TOKEN}`)
}
/* Options
Global options
stages - Ramping pattern
thresholds - pass/fail criteria for the test
*/
export let options = {
stages: [
// Linearly ramp up from 1 to maximum VUs during first minute
{ target: (__ENV.MAX_VIRTUAL_USERS), duration: (__ENV.VIRTUAL_USERS_RAMP_UP_DURATION || '1m') },
// Hold at maximum VUs for the next 3 minutes and 30 seconds
{ target: (__ENV.MAX_VIRTUAL_USERS), duration: (__ENV.VIRTUAL_USERS_SUSTAINED_DURATION || '3m30s') },
// Linearly ramp down from maximum VUs to 0 VUs over the last 30 seconds
{ target: 0, duration: (__ENV.VIRTUAL_USERS_RAMP_DOWN_DURATION || '30s') },
// Total default execution time will be ~5 minutes
],
thresholds: {
// We want the 95th percentile of all HTTP request durations to be less than 500ms
http_req_duration: ['p(95)<250'],
// Thresholds based on the custom metric we defined and use to track application failures
check_failure_rate: [
// Global failure rate should be less than 1%
'rate<0.01',
// Abort the test early if it climbs over 3%
{ threshold: 'rate<=0.03', abortOnFail: true },
],
},
}
export default function main() {
example1Tests(session)
example2Tests(session)
}