-
-
Save RobinJDCox/b42adf57688357c4c99f7c255a84775b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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