Skip to content

Instantly share code, notes, and snippets.

@RobinJDCox
Created November 24, 2021 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RobinJDCox/b42adf57688357c4c99f7c255a84775b to your computer and use it in GitHub Desktop.
Save RobinJDCox/b42adf57688357c4c99f7c255a84775b to your computer and use it in GitHub Desktop.
import io.gatling.core.Predef._
import io.gatling.core.scenario.Simulation
import io.gatling.core.structure.ScenarioBuilder
import io.gatling.http.Predef._
import io.gatling.http.protocol.HttpProtocolBuilder
import scala.concurrent.duration._
class ExampleSimulation extends Simulation {
private def httpBuilder: HttpProtocolBuilder = http
.shareConnections
.asyncNameResolution()
.maxConnectionsPerHost(1)
setUp(
creator
.inject(atOnceUsers(1))
.noShard
.andThen(
healthCheck
.inject(atOnceUsers(1))
.noShard
.andThen(
mainScenario
.inject(atOnceUsers(1))
.protocols(httpBuilder)
)
)
)
// This step is where the simulation should fail completely if a condition is met
// The following steps should not be executed if this fails
def creator: ScenarioBuilder =
scenario("Initialise Database").exec( _ =>
throw new Exception("Error during database population")
)
.exitHereIfFailed
.stopInjector("Error during database population")
// This also sometimes fails without actually terminating the simulation
def healthCheck: ScenarioBuilder =
scenario("Health Check").exec(
http("Health Check")
.get("http://localhost:9000/health")
.check(status is 200)
)
// The main scenario, which I only want to run if the previous steps succeed
def mainScenario: ScenarioBuilder =
scenario("Main scenario")
.repeat(2) {
exec { session =>
println("Some HTTP call...")
session
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment