3

I am performance testing a Play! application which contains a number of GET/POST API's. I want to do some debugging as one single test is mysteriously failing out of hundreds (and it only fails when the whole lot is run). How do I conditionally add println's if the status returned is 500?

I have tried the following, but since session.status isn't an Int it isn't working (ie it always returns false). Also, I don't think that checking session.status is even the right thing to do as when I just print out session.status for every call, it just spits a bunch of lines of OK (not even SEE_OTHER or something similar like I would expect it to be for the successful runs), but I'm not sure what the alternative is.

val postData: ChainBuilder = exec(http(s"[POST] Data sent to API")
  .post(s"$baseUrl/post-data")
  .formParam("id", s"$${id}")
  .check(status.is(303))
  .disableFollowRedirect)
  .exec {
    session =>
      if (session.status == 500) {
        println(session.attributes("id")) // whatever
      }
      session
  }

I'm not sure how to do this if check, or where to put it. How do I conditionally check some data within my tests, based on the status of the result?

James Whiteley
  • 3,363
  • 1
  • 19
  • 46

2 Answers2

0

Give the below your try

exec(Actions.Job()).pause(Configuration.THINK_TIME_AFTER_PUT second)
.asLongAs(session => (session("responseStatus").as[String], session("statusCode").as[Int], session("reqInfo").as[String])) {
          println ("test")

}
user666
  • 1,104
  • 12
  • 20
0

You're trying to do it the hard way. Gatling has good logging with the Log4J infrastructure, but most places on the internet tell you to use a log4j.xml file but I think that is harder than just enabling Gatling debug in the test using Scala code:

This is just an example. You could simplify this down and add this code at the start of your Gatling test :

  val LOG_LEVEL = sys.env.getOrElse("LOG_LEVEL", "WARN")

  val context: LoggerContext = LoggerFactory.getILoggerFactory.asInstanceOf[LoggerContext]

  if (LOG_LEVEL.equals(Level.TRACE)) {
    context.getLogger("io.gatling.http.engine.response").setLevel(Level.valueOf(LOG_LEVEL))
  } else if (LOG_LEVEL.equals(Level.DEBUG)) {
    context.getLogger("io.gatling.http.engine.response").setLevel(Level.valueOf("DEBUG"))
  } else {
    context.getLogger("io.gatling.http").setLevel(Level.valueOf("INFO"))
  }
djangofan
  • 28,471
  • 61
  • 196
  • 289