Hi All, my application has known cookie in the test environment that I can use to start my performance test but part of that cookie changes in subsequent requests. Each virtual user I start can use that cookie the first time but then I have to change dynamically for the 2,3,4,nth time that vUser sends a request. In other words if I start with 10 vUsers I will get 10 passed requests but then All other requests will fail with a 401. This is my code, and I guess I am not setting the AWSALB after the first time through per vUser. Any suggestions? Will setting a flag at start time to false and using a doIfOrElse statement work?
This is the header stuff
public class BaseSimulation extends Simulation {
public static Map<String, String> getSessionHeadersWithAWSALB(){
Map<String, String> sessionHeaders = new HashMap<String, String>();
sessionHeaders.put("Content-Type", "application/json");
sessionHeaders.put("accept", "application/json");
sessionHeaders.put("x-requested-with", "XMLHttpRequest" );
sessionHeaders.put("pragma", "no-cache");
return sessionHeaders;
}
}
This is the API call
public class Metrics extends BaseSimulation {
public static final ChainBuilder requestSomeMetricsHours =
feed(jsonFile("cda/somemanager/zones.json").random())
.doIfEquals("#{accessible}", true).then(
feed(dateHourFeeder)
.exec(http("Some Metrics Request")
.post("/api/v1/some/Metrics")
.headers(getSessionHeadersWithAWSALB())
.header("COOKIE", "X-Token=fdbcac451beba3c93e2f8b08a7919e210081f1813e4d6dddf83777cb3347e0f9; AWSALB=#{awsalb}; AWSALBCORS=#{awsalb}")
.body(ElFileBody("payloads/getSomeManagerMetrics.json")).asJson()
.check(status().is(200))
.check(status().saveAs("status"))
.check(bodyString().saveAs("responseBody"))
.check(headerRegex("Set-Cookie", "AWSALB=(.*?);").saveAs("awsalb"))
.check(jsonPath("$.endTime").exists().saveAs("endTime"))
.check(jsonPath("$.startTime").exists().saveAs("startTime"))
).exec(session -> {
System.out.println(session.getString("awsalb"));
return session;
})
);
}
public class SomeMetricsRequestsScenarios {
public static final ScenarioBuilder scnSomeMetricsRequestsHoursScenario = SomeMetricsRequestsScenariosChains("Request Some Metrics Hourly",
Metrics.requestSomeMetricsHours
);
public static ScenarioBuilder SomeMetricsRequestsScenariosChains(String name, ChainBuilder... chains) {
return scenario(name).forever().on(
exec(session -> {
Session awsalb = session.set("awsalb", "w5rhjuzJtx55UIcWx0jkmJHqXQrXavnXMma/XcR4WbZJofhSCo4aPbtNAmDIAhwGyuE9s0Y61s85D6qQOiAnZxqI6iOW3z6iqvBVPjoIeI+6UwuomNkz5xVs0aMT");
return awsalb;
})
.exec(List.of(chains))
.pause(2)
);
}
}
Simulation Code
public class EnergyMetricsRequestsSimulation {
HashMap<String, List<PopulationBuilder>> scenario = new HashMap<>();
{
scenario.put("EnergyMetricsRequestHours",
List.of(SomeMetricsRequestsScenarios.scnSomeMetricsRequestsHoursScenario.injectOpen(rampUsers(PerformanceProperties.userCount())
.during(PerformanceProperties.rampDuration()))
.protocols(httpProtocol))
);
}
{
setUp(scenario.get(PerformanceProperties.testScenario()))
.maxDuration(Duration.ofSeconds(PerformanceProperties.testDuration()))
.protocols(httpProtocol);
}
I run the code with following mvn command
mvn gatling:test -Dgatling.simulationClass=com.cisco.performance.simulations.SomeMetricsRequestsSimulation -DvUsers="10" -DrampDuration="1" -DtestDuration="300" -DtestScenario="SomeMetricsRequestHours" -DmetricsHours="1"