How to set a specific timeout for a particular simulation?


I’m in need of advice, commentary, or guidance if someone faced something similar to this.

I have a set of simulations that use the same tolerance criteria regarding timeouts, but I do have one that needs some different values. And I do want to run them all with just ‘sbt gatling:test’
I can’t change the ‘gatling.conf’ file as that would modify the behavior of all other simulations as well.
As documented in the configuration section of Gatling’s docs, System properties > gatling.conf > gatling-defaults.conf, so my only chance to run all simulations without touching the config file is to use system properties to momentarily change Gatling’s tolerance, but after arranging something like the following I’ve discovered that it wouldn’t work this way


import project.http.Http

class MySimulation extends Simulation {

val readTimeoutProperty = “gatling.http.ahc.readTimeout”
val requestTimeoutProperty = “gatling.http.ahc.requestTimeout”
val originalReadTimeout = System.getProperty(readTimeoutProperty)
val originalRequestTimeout = System.getProperty(requestTimeoutProperty)

System.setProperty(readTimeoutProperty, “60”)
System.setProperty(requestTimeoutProperty, “60”)
System.out.println(readTimeoutProperty + " = " + System.getProperty(readTimeoutProperty))
System.out.println(requestTimeoutProperty + " = " + System.getProperty(requestTimeoutProperty))

val myScenario: ScenarioBuilder = scenario("Scenario description)


System.setProperty(readTimeoutProperty, originalReadTimeout)
System.setProperty(requestTimeoutProperty, originalRequestTimeout)



Instead I’ve discovered that system properties are read and used to prepare the simulation even before than when creating my own simulation class, somewhere in the parent class. This can be confirmed by executing the simulation via SBT while setting the desired system properties like this:

sbt -Dgatling.http.ahc.readTimeout=60 -Dgatling.http.ahc.requestTimeout=60 "gatling:testOnly project.simulations.MySimulation"

So while executing the simulation like this I actually got the intended behavior, so now I know that my HOCONs are right, and it is of no use to change the system properties inside the simulation class.

I’m left with two options it seems now:

  1. To somehow programatically change Gatling’s expectations before my class is set, which sounds complex although it would allow me to stick to just being able to run everything altogether with ‘sbt gatling:test’.
  2. Renounce to be able to run all simulations with one command and create custom SBT tasks to run things separately and with their own configurations if needed.

Option 2 would allow me to create larger tasks to sequentially execute smaller different tasks with their own configurations too, emulating the first option’s usage, at the cost of recompiling times due to the extra Gatling runs.

Any comment or insight will be welcome.