Hello folks. I have a dilemma. I have a use case where a required access token expired within a period of time that requires a token refresh at least twice during a performance test. the test script is named after two scenarios which are executed. with all stages the test run is 28min. I"m using the exec.scenario.startTime function but the problem is that during the first scenario the “expired” value properly meets the condition to enter the “if statement”, call for a new token. however during the second scenario I’m finding it challenging to reset the “expired” variable in a manner that will again meet the condition to call for a new token when the timed period meets the expired threshold. say for instance. every 5min I need to call for a new token. this works for the first scenario using exec.scenario.startTime, however during the second scenario the call for a new token never occurs. The attempt below is to multiply the expiration time by a multiplier each time the token expires during the test run. the first instance multiply =1. when the timer expires multiply is incremented by 1. then the token_expiration constant is doubled and tripled as needed and evaluated against “expired” as it increases from exec.scenario.startTime
Is there some trick to reset exec.scenario.startTime between scenario’s? does someone have an example?
scenario’s:
scenarios: {
peak: {
// peak scenario name
executor: 'ramping-arrival-rate',
startRate: 0,
timeUnit: '1s',
preAllocatedVUs: 50,
maxVUs: 3000,
stages: [
{ target: peak, duration: peak_ramp },
{ target: peak, duration: peak_sustain },
{ target: 0, duration: ramp_down },
],
gracefulStop: after_peak_delay, // do not wait for iterations to finish in the end
tags: { test_type: 'peak' }, // extra tags for the metrics generated by this scenario
exec: 'peak_gate_rush', // the function this scenario will execute
},
gate_rush: {
// gate_rush scenario name
executor: 'ramping-arrival-rate',
startRate: 0,
startTime: start_delay,
timeUnit: '1s',
preAllocatedVUs: 50,
maxVUs: 3000,
stages: [
{ target: gate_rush, duration: gr_ramp },
{ target: gate_rush, duration: gr_sustain },
{ target: 0, duration: ramp_down },
],
gracefulStop: after_peak_delay, // do not wait for iterations to finish in the end
tags: { test_type: 'gate_rush' }, // extra tags for the metrics generated by this scenario
exec: 'peak_gate_rush', // the function this scenario will execute
},
},
test code:
export function peak_gate_rush() {
// The first VU iteration will always perform a login operation in order to get an API
// token we need to access the API end point that we want to test
expired = `${new Date() - new Date(exec.scenario.startTime)}`;
if (api_token === null || expired >= token_expiration * multiply) {
if (expired >= subs_token_expiration * multiply) {
multiply += 1;
}
// console.log(`step1: scenario ran for ${new Date() - new Date(exec.scenario.startTime)}ms`);
**var res = get_token(); // NEED THIS EXECUTED EVERY 5MIN.**
var res_json = JSON.parse(res.body);
token = res_json['access_token'];
}
// Below is the actual test case for the API endpoint
group("v1_API", function () {
var res = v1_API(api_token);