我想在http请求中添加条件。喜欢这种情况, 使用API,
我有一个动作,我找到了'行动ID'
使用“行动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)
}
请帮忙。感谢
答案 0 :(得分:3)
试试这个asLongAs(session => session.attributes(response) != "MY STATUS") {
exec( http().get(). .check(xpath("//status").saveAs(response) ) }
所以基本上这将继续运行直到响应的值不等于我的状态。
您还可以在asLongAs中添加其他短路条件。