[英]How to fail a Gatling test from within “exec”?
帶有 exec 鏈的 Gatling 場景。 請求后,返回的數據被保存。 后來它被處理,根據處理結果,它應該失敗或通過測試。
這似乎是最簡單的可能場景,但我找不到任何可靠的信息如何從 exec 塊中使測試失敗。 斷言打破了場景,看起來像是加特林(如:異常拋出不僅沒有通過測試)。
例子:
// The scenario consists of a single test with two exec creating the execChain
val scn = scenario("MyAwesomeScenario").exec(reportableTest(
// Send the request
exec(http("127.0.0.1/Request").get(requestUrl).check(status.is(200)).check(bodyString.saveAs("MyData")
// Process the data
.exec(session => {
assert(processData(session.attributes("MyData")) == true, "Invalid data");
})
))
在“監護人失敗,正在關閉系統”的某處場景之上。
現在這似乎是一個有用的、經常使用的事情——我可能遺漏了一些簡單的東西。 怎么做?
您必須遵守 Gatling API。
processData
,通常在轉換可選步驟中。你在尋找類似的東西嗎
.exec(http("getRequest")
.get("/request/123")
.headers(headers)
.check(status.is(200))
.check(jsonPath("$.request_id").is("123")))
因為編輯隊列已經滿了。
這已經在新版本的 Gatling 中得到解決。 版本 3.4.0
他們補充說
exitHereIf("${myBoolean}")
exitHereIf(session => true)
如果條件成立,讓用戶從這一點退出場景。 條件參數是一個 Expression[Boolean]。
我使用exitHereIfFailed
實現了一些聽起來就像你想要完成的東西。 我通常在虛擬用戶嘗試登錄后使用它。
exitHereIfFailed
是這樣使用的
val scn = scenario("MyAwesomeScenario")
.exec(http("Get data from endpoint 1")
.get(request1Url)
.check(status.is(200))
.check(bodyString.saveAs("MyData"))
.check(processData(session.attributes("MyData")).is(true)))
.exitHereIfFailed // If we weren't able to get the data, don't continue
.exec(http("Send the data to endpoint 2")
.post(request2Url)
.body(StringBody("${MyData}"))
如果exitHereIfFailed
之前的任何檢查失敗,則此場景將在exitHereIfFailed
處exitHereIfFailed
中止。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.