Measure the performance of a secured http service

Hi,

I have the following scenario where I want to measure the performance of a http service. I have eventually to perform a login http request if a cookie is not present in the session, and then I call the http service. My issue is that the doIf always returns false.

def loginRequest: HttpRequestBuilder = {
val url = “http://server:port/users/access”

http(“post_login_users”)
.post(url)
.header(“Cache-Control”, “no-cache”)
.header(“Content-Type”, “application/json”)
.basicAuth("${email}", “${password}”)
.check(status.find.in(200, 204))
}

def serviceRequest: HttpRequestBuilder = {
val url = “http://server:port/service”

http(“post_login_users”)
.post(url)
.header(“Cache-Control”, “no-cache”)
.header(“Content-Type”, “application/json”)
.check(status.find.in(200, 204))
}

val scn = scenario(“myscenario”).feed(csv(“csvPath”).circular).during(duration) {
.doIf(!_.contains(“cookieName”)) {
exec(loginRequestFunc)
}
.exec {
session => println(session.contains(secCookieName))
session
}
.exec(serviceRequest)
}

Also, I’d like to know what’s the best approach to measure the performance of the service request without being biased by the login request latencies? Is it possible to perform previously the login in the before {} block and store the “email, password, cookie” in another CSV, and then inject the cookies?

What’s the best approach?

Thanks in advance.
Sofiane

Hi,

Cookies are stored in a CookieJar which is stored in the Session, so “session.contains(“cookieName”)” can’t work.
You have to first fetch the CookieJar, and then check the existence of the cookie. Print the session for find out the CookieJar key.

Hi Stephane,

Thanks for the reply.

I am generating a CSV in the before block which will be used as the scenario feeder. The problem is that the setUp tries to access the feeder before the CSV has been generated:

[error] java.lang.IllegalArgumentException: Could not locate feeder file; file <file_path> doesn’t exist

Would it make sense to assign the setUp call to a lazy val and then call it in the last statement of before block? if not, what’s the best way?

Thanks

Hi,

I’m not sure when Gatling actually loads the CSV files to be used by the feeders. However, you don’t need to generate a CSV file at all. As a matter of fact, you can make a feeder out of a Map[String, String], using and Iterator[Map[String, String]], each map representing a knew entry in you CSV file mapped by the columns names.

I’m not sure a by name parameter would work well with the current varags setUp signature. Please give it a try and contribute :slight_smile: