【发布时间】:2017-02-11 02:20:34
【问题描述】:
我想在 http 请求上添加条件。像这样的场景, 使用 API,
我有一个操作可以从中找到“操作 ID”
使用“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