Reputation: 859
I want to add one condition in below scenario.
I would like to Exit from the scenario if(counter=8 or WorkflowStatus=true)
Does anyone knows how to add a counter which increases on every request upto 8 times and exit after 8, and above condition if request gets WorkflowStatus=true then exit in below scenario?
Let me know if you need more clarification. Thanks.
class LaunchResources extends Simulation {
val scenarioRepeatCount = Integer.getInteger("scenarioRepeatCount", 1).toInt
val userCount = Integer.getInteger("userCount", 1).toInt
val UUID = System.getProperty("UUID", "24d0e03")
val username = System.getProperty("username", "p1")
val password = System.getProperty("password", "P12")
val testServerUrl = System.getProperty("testServerUrl", "https://someurl.net")
val httpProtocol = http
.baseURL(testServerUrl)
.basicAuth(username, password)
.connection("""keep-alive""")
.contentTypeHeader("""application/vnd+json""")
val headers_0 = Map(
"""Cache-Control""" -> """no-cache""",
"""Origin""" -> """chrome-extension://fdmmgasdw1dojojpjoooidkmcomcm""")
val scn = scenario("LaunchAction")
.repeat (scenarioRepeatCount) {
exec(http("LaunchAResources")
.post( """/api/actions""")
.headers(headers_0)
.body(StringBody(s"""{"UUID": "$UUID", "stringVariables" : {"externalFilePath" : "/Test.mp4"}}"""))
.check(jsonPath("$.id").saveAs("WorkflowID")))
.exec(http("SaveWorkflowStatus")
.get("""/api/actions/{$WorkflowID}""")
.headers(headers_0)
.check(jsonPath("$.status").saveAs("WorkflowStatus")))
}
setUp(scn.inject(atOnceUsers(userCount))).protocols(httpProtocol)
}
Upvotes: 0
Views: 1130
Reputation: 1665
Personally I use this tricks to have a counter increments at every request
val scn = scenario("Scenario Conversion")
.exec{session => session.set("number",session.userId.split("-").last.toInt)}
You can reuse this in another session value
val scn = scenario("Scenario Conversion")
.exec{session => session.set("number",session.userId.split("-").last.toInt)}
.exec{session => session.set("timestamp", nextDay(session("number").as[Int]/1000))}
Upvotes: 1
Reputation: 320
You can use Redis to storage your count number, control Redis Number every time when request is comming. I Use Redis to count my http post count in 3 minutes, If the count is over 10 times in 3 minutes, I will disable this post Ip Address, And this ip will get 403 forbidden error in future 3 minutes.
Upvotes: 0