Scala object is initialized in setUp. Why not in before?

Hi,

I have a configuration (Config in below code) object, that I use for reading properties and system variables.
In below code Config is addressed both form before and setUp. But it’s initialized in setUp.
The result is that values, which are populated in Config, are nulls because before part was not done yet.

import com.bk.cfg.Config
import com.bk.core.Tests
import io.gatling.core.Predef._
import io.gatling.core.scenario.Simulation
import io.gatling.http.Predef.http
import scala.concurrent.duration._

class SomeTest extends Simulation {
val logger = org.slf4j.LoggerFactory.getLogger(“SomeTestLogger”)
var appProtocol =
http
.baseUrl(“https://hostname”)
.acceptHeader(“text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,/;q=0.8”)
.acceptEncodingHeader(“gzip, deflate, br”)
.acceptLanguageHeader(“en-US,en;q=0.9,he;q=0.8”)
.disableCaching
.connectionHeader(“keep-alive”)

before{
logger.info(“Start test”)
val testId = doSomeHttpCall()
sys.props.put(“id”,testId)
val users = Config.users
logger.info(“Starting simulation”)
}

setUp(
Tests.MyScenario
.inject(rampUsers(10).during(60 seconds))
)
.protocols(appProtocol)
.maxDuration(Config.maxDuration)
}

This is the log:

12:41:26.383 [INFO ] i.g.c.c.GatlingConfiguration$ - Gatling will try to use ‘gatling.conf’ as custom config file.
12:41:26.920 [INFO ] a.e.s.Slf4jLogger - Slf4jLogger started
12:41:27.370 [INFO ] ConfigLogger - Run Config
12:41:27.372 [INFO ] ConfigLogger - loadEnvProperties
12:41:27.378 [INFO ] ConfigReaderLogger - Done loading environment configuration
12:41:27.378 [INFO ] ConfigLogger - loadSimulationProperties
12:41:27.379 [INFO ] ConfigReaderLogger - Using default configuration file…
12:41:27.379 [INFO ] ConfigReaderLogger - Done loading simulation configuration
12:41:27.401 [INFO ] SomeTestLogger - Start test

12:41:27.406 [INFO ] SomeTestLogger - Starting simulation

As you can see, Config is loaded before the ‘before’ stage.
If Config reference is removed from setUp, the log entries will be reversed (SomeTestLogger, then ConfigLogger).

https://github.com/gatling/gatling/commit/a85cad7d4faaccc8f3271eaff3e72cb6ab0cb65b