global variables and "before" block

91 views
Skip to first unread message

script learner

unread,
May 17, 2021, 12:58:19 PM5/17/21
to Gatling User Group
Hi All, 
I am trying to use a global variable to host a bunch of test parameters, but I don't see expected values.  For example (see [1] below), even if I set nbUsers to 5 in properties file, actual test results will show nbUsers is set to 2.  The logging messages inside "before" block do show that nbUsers is set to 5 though.  Can you please kindly point out what is the right way to do it?  I am using Gatling 3.5.1.

Thanks
Henry

[1]
class MyTestSimulation2 extends Simulation {
  val logger = org.slf4j.LoggerFactory.getLogger("TestLogger")
  val props = new Properties()

  before {
    val file = new File("/opt/gatling/conf/gatling.properties")
    if (file.exists()) {
      val fileReader = new FileReader("/opt/gatling/conf/gatling.properties")
       props.load(fileReader)
     }
    else {
       logger.error("/opt/gatling/conf/gatling.properties does NOT exist!");
     }
     logger.info("nbUsers: " + props.getProperty("nbUsers", "2"))
     logger.info("duration: " + props.getProperty("duration", "60"))
   }
....
  setUp(scnRunExec.inject(constantConcurrentUsers(props.getProperty("nbUsers", "2").toInt)
during(props.getProperty("duration", "60").toInt))).protocols(httpProtocol)

Stéphane LANDELLE

unread,
May 17, 2021, 1:13:45 PM5/17/21
to gat...@googlegroups.com
https://gatling.io/docs/current/general/simulation_structure/#hooks

Don't put this code in the before block.

Logo Stéphane Landelle
Chief Technical Officer
twitter: @slandelle
site:
gatling.io




--
You received this message because you are subscribed to the Google Groups "Gatling User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gatling+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gatling/5dd4c98a-5956-4115-a5e6-d444baf2a851n%40googlegroups.com.

script learner

unread,
May 17, 2021, 3:40:14 PM5/17/21
to Gatling User Group
Thanks Stephane.  It works after I removing "before {" and "}".  So the before and after block are there for some presetup and tear down work with our own codes (no Gatling DSL) .
Reply all
Reply to author
Forward
0 new messages