I define a custom checker, but I cant set attribute to the session in checker

Hi guys, I want to check data in the database or Redis, etc., and want to show check results on result reports. so I define a custom checker to meet this requirement. but not usable, and I’m not familiar with scala and Gatling DSL, so I want to ask for your help.
this is what I wanted, to check data accuracy and extra some attributes then store it in session.


this is my checker


but I can not get the attribute in the custom checker or out of the checker, it throws “No attribute named ‘orderNo’ is defined”
my checker extends ExitableAction but if the check failed, exitHereIfFailed does not take effect.
so how can I set the attribute to the session and exit the workflow if the check failed

here’s the sample code repo: lance2038/gatling-integration-test-demo (github.com)
many thanks!


remove 2 issue codes, and here’s the result, the check fails but does not stop the workflow.

simulate query data from databse
image
so the check always failed

I didn’t dig into your repo. But keep in mind that session is immutable.

ie: when you wrote:

session.set("orderNo", orderDO.orderNo)

(source: CheckOrderBehavior.scala#L18)

you create a new session that contains your orderNo value… but you do nothing with that.

Note that your CustomSessionCheckBaseAction use a lot of internal Gatling classes, and such can change without notice. You’ll have to maintain it.

Cheers,

1 Like

thanks for your answer. I think the session is like java’s hashmap and can put k&v anywhere before, I will try to find another way to carry the attribute to the next session.
and check failed not to exit the workflow bcs I did not mark the session as succeed or failed

Also, please note that operations performed in Gatling DSL methods must be very fast or you’ll block the event loop. In particular, you shouldn’t perform a database call in each check execution.

1 Like

I guess you wanted something like code below, but as slandelle said above, it would be better to perform such checks after test end. It can create additional load on your database.

object CheckOrderBehavior {

  val checkOrder: ChainBuilder = {
    exec { session => //don't know how to write it in scala function
      val orderDO = OrderSimulationRepository.findById(session("orderId").as[Int])
   
      //return session copy with orderNo on success or mark as failed if error
      if ("ACTIVE" == orderDO.orderState) {
        session.set("orderNo", orderDO.orderNo)
      } else {
        session.markAsFailed
      }
    }.exitHereIfFailed
      .exec(session => {
        // get orderNo from session, but can not find 'orderNo' in session
        session
      })
  }

}

it would be better to perform such checks after test end. It can create additional load on your database.

It’s way worse than this.
Gatling uses n EventLoop threads where n = 2 * cores. If you have a 4 core machine, every time you’re blocking an EventLoop thread for 100ms, you’re actually blocking 1/8th of your virtual users for this same time.

1 Like

Haha, thanks for reminding me. But we use Gatling not for performance testing, but for integration testing to reduce the workload of QA.
Because Gatling is simple and easy to use, and friendly for Java developers, so we chose Gatling and we don’t need to worry about performance

thanks for your reply. I mark the session failed/succeed status at common.checker.actions.CustomSessionCheckBaseAction#execute.
and we use the Gatling not for the performance testing but integration testing. so doesn’t need to care about the performance. thx :heart:

it’s very important for the developers who use Gatling to do the loading test. I very like Gatling, so use Gatling to do the integration test. and do your guys consider developing a framework for integration testing :see_no_evil: