How can I abort a Gatling simulation if the test system is not in the right state?

Viewed 313

The target system I am load testing has a mode that indicates if it's suitable for running a load test against.

I want to check that mode once only at the beginning of my simulation (i.e. I don't want to do the check over and over for each user in the sim).

This is what I've come up with, but System.exit() seems pretty harsh.

I define an execution chain that checks if the mode is the value I want:

def getInfoCheckNotRealMode:ChainBuilder = exec(
  http("mode check").get("/modeUrl").
    check( jsonPath("$.mode").saveAs("mode") )
).exec { sess =>
  val mode = sess("mode").as[String]
  println(s"sengingMode $mode")

  if( mode == "REAL"){
    log.error("cannot allow simulation to run against system in REAL mode")
    System.exit(1)
  }

  sess
}

Then I run the "check" scenario in parallel to the real scenario like this:

val sim = setUp(
  newUserScene.inject(loadProfile).
    protocols(mySvcHttp),
  scenario("Check Sending mode").exec(getInfoCheckNotRealMode).
    inject(atOnceUsers(1)).
    protocols(mySvcHttp)
)

Problems that I see with this:

  • Seems a bit over-complicated for simply checking that the system-under-test is suitable for testing against.
  • It's going to actually run the scenarios in parallel so if the check takes a while it's still going to generate load against a system that's in the wrong mode.
  • Need to consider and test what happens if the mode check is not behaving correctly

Is there a better way?

Is there some kind of "before simulation begins" phase where I can put this check?

0 Answers
Related