gpt4 book ai didi

performance - 使用加特林将条件放入 HTTP 请求中

转载 作者:行者123 更新时间:2023-11-28 20:05:47 25 4
gpt4 key购买 nike

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

  1. 我从找到“操作 ID”的位置执行一项操作

  2. 使用该“操作 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
}

下面是我做的代码片段,

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

请帮忙。谢谢

最佳答案

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

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

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

关于performance - 使用加特林将条件放入 HTTP 请求中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39826515/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com