Try to check back-end is UP before starting simulation

Hello everybody,

I try to check if my Spring Boot back-end is UP before starting the whole simulation.

I guess I could do so using the doWhileDuring loop.

I tried something like this with no success:

doWhileDuring(
  condition = "${isUp}",
  duration = 1 minute,
  counterName = "Wait for microservice to be up"
) {
  exec(
    http(
      requestName = "HealthCheck"
    ).get(
      url = "/actuator/health"
    ).check(
      bodyString.is(
        expected = """{"status":"UP"}"""
      ).saveAs("isUp")
    )
  )
}

But the way I save the isUp variable may not be the right one and the loop doesn’t lock the launch of the Simulation.

Could you help me to find the good way to do so?

Thanks in advance.

Regards,
Romain.

  • edit
doWhileDuring(
  condition = "${!isUp}",

maybe the following way to save the status?

doWhileDuring(
  condition = "${!isUp.equalsIgnoreCase(\"UP\")}",
  duration = 1 minute,
  counterName = "Wait for microservice to be up"
) {
  exec(
    http(
      requestName = "HealthCheck"
    ).get(
      url = "/actuator/health"
    ).check(
      jsonPath("$.status").saveAs("isUp")
    )
  )
}

But does not work.

First, I would argue this is not a test responsibility but should be the test launcher’s.

Please have a look at Gatling EL doc for what you can and can’t do: https://gatling.io/docs/current/session/expression_el
And then have a look at Gatling Session API: https://gatling.io/docs/current/session/session_api

Note: In next release, you’ll be able to use sequential scenarios: https://github.com/gatling/gatling/issues/3830

You mean that the test launcher’s (gradle in my case) must implement the waiting logic such as: http://brokenrhythm.blog/gradle-gatling-springboot-automation

?
I find it pretty boilerplate and hope something smoother with doWhileDuring :frowning:

IMHO, the component in charge of spawning your test environment should also take care of waiting for it to be up before launching the load test.
It’s an orchestration concern and typically something you would implement as a CI pipeline, eg with Jenkins.

But then, it’s up to you, you can do whatever you want.
I don’t recommend doing this in the actual test, as it will mess you with your virtual users.
You could write your own code, possibly in Java, to wait and block in the “before” hook, see https://gatling.io/docs/current/general/simulation_structure/#hooks

Your advice is very wise.
I’ll consider the CI way.
Thanks for the link about the hooks, seems very nice.