簡體   English   中英

如何在“exec”中讓 Gatling 測試失敗?

[英]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。

  1. 通過檢查,您不會“失敗”測試,而是“失敗”請求。 如果您正在尋找整個測試失敗的情況,您應該查看斷言API 和Jenkins 插件
  2. 您只能在請求站點執行檢查,而不能稍后執行。 一個很好的原因是,如果您像正在做的那樣將 bodyString 存儲在 Sessions 中,您將最終使用大量內存並且可能會崩潰(仍然被引用,因此不能被垃圾回收)。 您必須在檢查中執行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之前的任何檢查失敗,則此場景將在exitHereIfFailedexitHereIfFailed中止。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM