0

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)
}
Peter
  • 855
  • 2
  • 15
  • 35

2 Answers2

1

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))}
crak
  • 1,635
  • 2
  • 17
  • 33
  • Thanks for the answer @crak. If possible can you pls help me out on this issue? I want to put KO status if my count is greater than 8 OR FailedStatus = true. Pls have a look. http://stackoverflow.com/questions/39991234/how-to-add-status-ko-in-gatling-script – Peter Oct 13 '16 at 10:43
  • @peter can you use session("number") in check function? – crak Oct 13 '16 at 11:52
  • How?? any syntax or example?? – Peter Oct 13 '16 at 12:07
  • I never have to do that, I have no exemple to give you – crak Oct 13 '16 at 12:28
0

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.

haiyang
  • 310
  • 3
  • 8
  • Just implemented this, .asLongAs(session => session.attributes("WorkflowStatus") != "false" && count.getAndIncrement() < 8) {...} and it worked. – Peter Oct 05 '16 at 12:47
  • How do I make those requests failed? Like, I have 3 conditions in below code, 1. If request Count > 8 then exit from the loop 2. If WorkflowStatus == False then exit from the loop 3. If WorkflowFailed == True then exit from the loop There are chances that many requests get failed in any of the above conditions, such as if WorkflowStatus didn't get 'True' even after triggering request 8 times then that request should be failed. but instead of showing that in failed count it shows in success count. How do I count and display failed request which are failed in above conditions – Peter Oct 06 '16 at 13:31