【问题标题】:Put condition in HTTP request using gatling使用 gatling 将条件放入 HTTP 请求中
【发布时间】:2017-02-11 02:20:34
【问题描述】:

我想在 http 请求上添加条件。像这样的场景, 使用 API,

  1. 我有一个操作可以从中找到“操作 ID”

  2. 使用“Action Id”检查“正在运行/等待/已完成/等”该操作的状态并将其保存在变量中

我做了这两个步骤,现在我想做

3.如果状态为“正在运行”,我必须每 20 分钟检查一次状态,如果状态 =“已完成”,则每 20 分钟重新检查一次状态,然后在 2 小时后自动退出或退出(即使状态处于运行状态)

编辑: 想放这样的条件,

Check status = true
{   
    pause for 15minutes
    request once again after 15minutes
    if(status = false)
    {
        exit
    }
    else
    {
        request once again and check status, if true wait for 15minutes
        If total waiting time is more than 2 hours then exit
    }
}
else
{
    exit
}

下面是我做的代码sn-p,

import io.gatling.core.Predef._
import io.gatling.http.Predef._
import scala.concurrent.duration._

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/{$wflowid}""")
                .headers(headers_0)
                .check(jsonPath("$.status").saveAs("WorkflowStatus")))

        .asLongAs(session => session.attributes("WorkflowStatus") != false) {
    pause(900)
    .exec(http("SaveWorkflowStatus")
            .get("""/api/actions/${WorkflowID}""")
            .headers(headers_0)
            .check(jsonPath("$.running").saveAs("WorkflowStatus")))

    }

        }


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

请帮忙。谢谢

【问题讨论】:

    标签: performance scala testing performance-testing gatling


    【解决方案1】:

    试试这个asLongAs(session => session.attributes(response) != "MY STATUS") { exec( http().get(). .check(xpath("//status").saveAs(response) ) }

    所以基本上这将继续运行,直到 response 的值不等于 MY STATUS 。

    您还可以在 asLongAs 中添加其他短路条件。

    【讨论】:

    • 感谢您的回答。我已经用我想要做的确切定义编辑了我的问题。你能帮我吗?编辑:想要这样设置条件,检查 status = true { ..... }
    • 我认为上面的peter也应该解决这个问题......你需要的是阻止操作20分钟,你可以尝试暂停......虽然我也没有尝试过
    • 我已经尝试使用 asLongAs 并在其中添加了 .pause() 但它会引发错误。传递 ${workflowStatus} 有问题。用错误更新了我的代码。请帮忙。谢谢。
    • 试试这个 session.attributes("WorkflowStatus") $ 不应该在那里...
    • 感谢 user666,它成功了。现在如何检查我的操作是否完成?我的意思是,一旦它进入 asLongAs 循环,该操作将等待 15 分钟 --> 然后再次请求如果得到状态 = true 然后退出 else 再次请求。每 15 分钟后至 2 小时。如何编码?再次感谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-08-27
    • 1970-01-01
    • 2021-05-09
    • 2021-09-05
    • 2020-12-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多