【问题标题】:How to add Status = KO in Gatling script?如何在 Gatling 脚本中添加 Status = KO?
【发布时间】:2017-02-20 19:41:41
【问题描述】:

我的请求有可能失败吗? 我想把 Status = KO 放在 asLongAs() 部分。我的情况是,如果我得到WorkflowFailed = TrueCount > 8,那么我想使用 Status = KO 来失败该请求。

我在某处看到过session.markAsFailed,但是如何以及在哪里使用它?

谢谢。

这是代码,

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 count = new java.util.concurrent.atomic.AtomicInteger(0)

    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")))

        }


     .asLongAs(session => session.attributes("WorkflowStatus") != "false" && count.getAndIncrement() < 8) {
        doIf(session => session("WorkflowFailed").validate[String].map(WorkflowFailed => !WorkflowFailed.contains("true")).recover(true)) 
        {
        pause(pauseTime)
        .exec(http("SaveWorkflowStatus")
                .get("""/api/actions/${WorkflowID}""")
                .headers(headers_0)
                .check(jsonPath("$.running").saveAs("WorkflowStatus"))
                .check(jsonPath("$.failed").saveAs("WorkflowFailed")))

        .exec(session => {
                val wflowStatus1 = session.get("WorkflowStatus").asOption[String]
                val wflowFailed1 = session.get("WorkflowFailed").asOption[String]
                println("Inner Loop Workflow Status: ========>>>>>>>> " + wflowStatus1.getOrElse("COULD NOT FIND STATUS"))
                println("Inner Loop Workflow Failed?? ========>>>>>>>> " + wflowFailed1.getOrElse("COULD NOT FIND STATUS"))
                println("Count =====>> " + count)
                session}) 

        }
        }   

    setUp(scn.inject(atOnceUsers(userCount))).protocols(httpProtocol)
}

【问题讨论】:

    标签: java scala performance-testing load-testing gatling


    【解决方案1】:

    会话中有一个可用的方法

    exec(session => session.markAsFailed)
    

    【讨论】:

      猜你喜欢
      • 2017-02-23
      • 2018-06-29
      • 1970-01-01
      • 1970-01-01
      • 2020-06-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-21
      相关资源
      最近更新 更多