Search code examples
scalagatling

Question about building custom RequestAction in Gatling


I followed this tutorial(https://blog.codecentric.de/en/2017/07/gatling-load-testing-part-2-extending-gatling/) which teaches you to extend Gatling and essentially led to building this plugin(https://github.com/rbraeunlich/gatling-jdbc) . I'm looking to build my own custom actions and have a small issue. Here's a simplified version of the code in my action (extends RequestAction):

override def sendRequest(requestName: String, session: Session): Validation[Unit] = {
  val start = clock.nowMillis
  if (requestName.toString().equals("abc")) {
    statsEngine.logResponse(session.scenario, session.groups, requestName.toString(), start, clock.nowMillis, OK, None, None)
    Success("success")
  } else {
    statsEngine.logResponse(session.scenario, session.groups, requestName.toString(), start, clock.nowMillis, KO, None, None)
    Failure("fail")
  }
}

For some reason when this action is invoked from exec the test remains active if result is OK. Any suggestions? (Apologies in advance if this is not the right forum)


Solution

  • In ActionBuilder#build

    def build(ctx: ScenarioContext, next: Action): Action
    

    You are given the next Action (consider it a callback).


    In RequestAction#sendRequest

    def sendRequest(requestName: String, session: Session): Validation[Unit]
    

    If you return a Failure, Gatling will consider the request "Failed to build" and automatically pass the execution to next.

    If you return a Success, it meant the request is sent. It is then up to you, when the request is completed, to log the response time and pass the execution to next.


    Since you never do that, Gatling consider the virtual user still "active".