1
1
import { sleep } from 'k6' ;
2
- import { createRealm , deleteRealm , createUser , generateRealms , getAccessToken , hitIntrospectionRoute , hitUserInfoRoute , createClient } from './helpers.js' ;
2
+ import {
3
+ createRealm ,
4
+ deleteRealm ,
5
+ createUser ,
6
+ generateRealms ,
7
+ getAccessToken ,
8
+ hitIntrospectionRoute ,
9
+ hitUserInfoRoute ,
10
+ createClient ,
11
+ } from './helpers.js' ;
3
12
import { user , client } from './constants.js' ;
4
13
5
14
let config = JSON . parse ( open ( __ENV . CONFIG ) ) ;
@@ -16,100 +25,99 @@ const OFFLINE = false;
16
25
const BASELINE_RATE = 34 ;
17
26
18
27
export const options = {
19
- scenarios : {
20
- peakProfile : {
21
- executor : 'constant-arrival-rate' ,
22
- duration : '2h' ,
23
- timeUnit : '1m' ,
24
- rate : 34 ,
25
- preAllocatedVUs : 5 ,
26
- } ,
27
- // stress: {
28
- // executor: 'ramping-arrival-rate', //Assure load increase if the system slows
29
- // startRate: 0,
30
- // timeUnit: '1m',
31
- // preAllocatedVUs: 10000,
32
- // stages: [
33
- // // Ramp in 100 req/sec intervals, and hold 5 mins.
34
- // // Each loop runs 3 req/sec, so (target * 3) / 60 = req/sec.
35
- // { duration: '5m', target: 2000 },
36
- // { duration: '5m', target: 2000 },
37
- // { duration: '5m', target: 4000 },
38
- // { duration: '5m', target: 4000 },
39
- // { duration: '5m', target: 6000 },
40
- // { duration: '5m', target: 6000 },
41
- // { duration: '5m', target: 8000 },
42
- // { duration: '5m', target: 8000 },
43
- // { duration: '5m', target: 10000 },
44
- // { duration: '5m', target: 10000 },
45
- // ],
46
- // }
47
-
48
-
49
- // stress: {
50
- // executor: 'ramping-arrival-rate', //Assure load increase if the system slows
51
- // startRate: BASELINE_RATE,
52
- // timeUnit: '1m',
53
- // preAllocatedVUs: 20000,
54
- // stages: [
55
- // { duration: '1m', target: BASELINE_RATE }, // just slowly ramp-up to a HUGE load
56
- // // just slowly ramp-up to an EPIC load.
57
- // { duration: '1h', target: 20000 },
58
- // ],
59
- // }
60
- } ,
61
- thresholds : {
62
- http_req_failed : [
63
- {
64
- threshold : `rate<${ MAX_ALLOWED_FAILURE_RATE } ` ,
65
- // Leave this in! Don't keep hammering the poor server after its failing, requests will queue
66
- abortOnFail : true ,
67
- } ,
68
- ] ,
69
- // Requests tend to drop after 60 second timeout. Can use below to fail earlier
70
- // http_req_duration: [
71
- // {
72
- // threshold: `p(95)<15000`,
73
- // abortOnFail: true,
74
- // },
75
- // ]
28
+ scenarios : {
29
+ peakProfile : {
30
+ executor : 'constant-arrival-rate' ,
31
+ duration : '2m' ,
32
+ timeUnit : '1m' ,
33
+ rate : 34 ,
34
+ preAllocatedVUs : 5 ,
76
35
} ,
36
+ // stress: {
37
+ // executor: 'ramping-arrival-rate', //Assure load increase if the system slows
38
+ // startRate: 0,
39
+ // timeUnit: '1m',
40
+ // preAllocatedVUs: 10000,
41
+ // stages: [
42
+ // // Ramp in 100 req/sec intervals, and hold 5 mins.
43
+ // // Each loop runs 3 req/sec, so (target * 3) / 60 = req/sec.
44
+ // { duration: '5m', target: 2000 },
45
+ // { duration: '5m', target: 2000 },
46
+ // { duration: '5m', target: 4000 },
47
+ // { duration: '5m', target: 4000 },
48
+ // { duration: '5m', target: 6000 },
49
+ // { duration: '5m', target: 6000 },
50
+ // { duration: '5m', target: 8000 },
51
+ // { duration: '5m', target: 8000 },
52
+ // { duration: '5m', target: 10000 },
53
+ // { duration: '5m', target: 10000 },
54
+ // ],
55
+ // }
56
+
57
+ // stress: {
58
+ // executor: 'ramping-arrival-rate', //Assure load increase if the system slows
59
+ // startRate: BASELINE_RATE,
60
+ // timeUnit: '1m',
61
+ // preAllocatedVUs: 20000,
62
+ // stages: [
63
+ // { duration: '1m', target: BASELINE_RATE }, // just slowly ramp-up to a HUGE load
64
+ // // just slowly ramp-up to an EPIC load.
65
+ // { duration: '1h', target: 20000 },
66
+ // ],
67
+ // }
68
+ } ,
69
+ thresholds : {
70
+ http_req_failed : [
71
+ {
72
+ threshold : `rate<${ MAX_ALLOWED_FAILURE_RATE } ` ,
73
+ // Leave this in! Don't keep hammering the poor server after its failing, requests will queue
74
+ abortOnFail : true ,
75
+ } ,
76
+ ] ,
77
+ // Requests tend to drop after 60 second timeout. Can use below to fail earlier
78
+ // http_req_duration: [
79
+ // {
80
+ // threshold: `p(95)<15000`,
81
+ // abortOnFail: true,
82
+ // },
83
+ // ]
84
+ } ,
77
85
} ;
78
86
79
87
export function setup ( ) {
80
- const accessToken = getAccessToken ( { username, password, clientId, confidential : true } ) ;
81
- const emptyRealms = generateRealms ( TOTAL_REALMS ) ;
82
- emptyRealms . forEach ( ( realm , i ) => {
83
- createRealm ( realm , accessToken ) ;
84
- const newUser = Object . assign ( { } , user , { username : `${ user . username } _${ i } ` } )
85
- createUser ( newUser , realm . realm , accessToken ) ;
86
- // Create a confidential client to be able to use the introspection endpoint with this realm
87
- createClient ( realm . realm , accessToken )
88
- } ) ;
89
- return emptyRealms ;
88
+ const accessToken = getAccessToken ( { username, password, clientId, confidential : true } ) ;
89
+ const emptyRealms = generateRealms ( TOTAL_REALMS ) ;
90
+ emptyRealms . forEach ( ( realm , i ) => {
91
+ createRealm ( realm , accessToken ) ;
92
+ const newUser = Object . assign ( { } , user , { username : `${ user . username } _${ i } ` } ) ;
93
+ createUser ( newUser , realm . realm , accessToken ) ;
94
+ // Create a confidential client to be able to use the introspection endpoint with this realm
95
+ createClient ( realm . realm , accessToken ) ;
96
+ } ) ;
97
+ return emptyRealms ;
90
98
}
91
99
92
100
export default function ( realms ) {
93
- realms . forEach ( ( realm , i ) => {
94
- const accessToken = getAccessToken ( {
95
- username : `${ user . username } _${ i } ` ,
96
- password : user . credentials [ 0 ] . value ,
97
- clientId,
98
- confidential : true ,
99
- realm : realm . realm ,
100
- offline : OFFLINE
101
- } ) ;
102
- hitUserInfoRoute ( accessToken , realm . realm )
103
- hitIntrospectionRoute ( accessToken , realm . realm , client . clientId , client . secret )
104
- } )
101
+ realms . forEach ( ( realm , i ) => {
102
+ const accessToken = getAccessToken ( {
103
+ username : `${ user . username } _${ i } ` ,
104
+ password : user . credentials [ 0 ] . value ,
105
+ clientId,
106
+ confidential : true ,
107
+ realm : realm . realm ,
108
+ offline : OFFLINE ,
109
+ } ) ;
110
+ hitUserInfoRoute ( accessToken , realm . realm ) ;
111
+ hitIntrospectionRoute ( accessToken , realm . realm , client . clientId , client . secret ) ;
112
+ } ) ;
105
113
}
106
114
107
115
export function teardown ( realms ) {
108
- // When stress testing, the enqueued requests can block teardown api requests from succeeding. Adding in a sleep to let the system recover a bit before trying to cleaunup.
109
- sleep ( 45 )
110
- console . log ( 'tearing down...' )
111
- const accessToken = getAccessToken ( { username, password, clientId, confidential : true } ) ;
112
- realms . forEach ( ( realm , i ) => {
113
- deleteRealm ( realm . realm , accessToken ) ;
114
- } ) ;
116
+ // When stress testing, the enqueued requests can block teardown api requests from succeeding. Adding in a sleep to let the system recover a bit before trying to cleaunup.
117
+ sleep ( 45 ) ;
118
+ console . log ( 'tearing down...' ) ;
119
+ const accessToken = getAccessToken ( { username, password, clientId, confidential : true } ) ;
120
+ realms . forEach ( ( realm , i ) => {
121
+ deleteRealm ( realm . realm , accessToken ) ;
122
+ } ) ;
115
123
}
0 commit comments