【问题标题】:Karate 0.9.5.RC5 - 'retry until' function somehow does not respect my 'retry' configuration in karate-config.js空手道 0.9.5.RC5 -“重试直到”功能不知何故不尊重我在 karate-config.js 中的“重试”配置
【发布时间】:2020-01-10 13:30:25
【问题描述】:

我有以下测试:

Feature: News API

  Background:
    * url baseUrl

  Scenario: get news index
    Given path "/"
    And retry until responseStatus == 200
    When method get
    Then status 200
    And match response contains "News service up and running"

和下面的 karate-config.js

function fn() {
    // get java system property 'karate.env'
    var env = karate.env;
    karate.log('karate.env system property was:', env);

    var config = {
        baseUrl: 'http://localhost:8080',
    };

    karate.configure('retry', {count: 5, interval: 6000});
    karate.configure('connectTimeout', 5000);
    karate.configure('readTimeout', 5000);

    return config;
}

使用 maven-failsafe-plugin 执行测试后控制台中出现以下错误:

...
[INFO] Running newsservice.NewsServiceIT
[main] INFO  o.a.http.impl.execchain.RetryExec - I/O exception (org.apache.http.NoHttpResponseException) caught when processing request to {}->http://localhost:8080: The target server failed to respond
[main] INFO  o.a.http.impl.execchain.RetryExec - Retrying request to {}->http://localhost:8080
[main] INFO  o.a.http.impl.execchain.RetryExec - I/O exception (org.apache.http.NoHttpResponseException) caught when processing request to {}->http://localhost:8080: The target server failed to respond
[main] INFO  o.a.http.impl.execchain.RetryExec - Retrying request to {}->http://localhost:8080
[main] INFO  o.a.http.impl.execchain.RetryExec - I/O exception (org.apache.http.NoHttpResponseException) caught when processing request to {}->http://localhost:8080: The target server failed to respond
[main] INFO  o.a.http.impl.execchain.RetryExec - Retrying request to {}->http://localhost:8080
[main] ERROR com.intuit.karate - org.apache.http.NoHttpResponseException: localhost:8080 failed to respond, http call failed after 2 milliseconds for URL: http://localhost:8080/
[main] ERROR com.intuit.karate - http request failed: 
org.apache.http.NoHttpResponseException: localhost:8080 failed to respond
---------------------------------------------------------
feature: classpath:newsservice/news/news-index.feature
scenarios:  1 | passed:  0 | failed:  1 | time: 0.7678
---------------------------------------------------------

HTML report: (paste into browser to view) | Karate version: 0.9.5.RC5
...

在测试开始之前,我启动了我的 Spring Boot 应用程序,这需要一些时间(约 5-7 秒),我知道测试没有成功,因为 Sprint Boot 应用程序尚未启动。

这就是为什么我尝试使用空手道的 retry until 功能来确保它在一段时间后重试。

但根据控制台输出,retry 配置似乎不受尊重。好像总是只试3次……

我还尝试在测试文件本身中设置 retry 配置,就像在空手道文档中一样:

* configure retry = { count: 10, interval: 5000 }

但这也没有用。

也许你有提示为什么它不起作用或者我仍然错过了什么?

感谢支持!

【问题讨论】:

    标签: java api spring-boot testing karate


    【解决方案1】:

    问题是retry until 仅在 HTTP 连接建立之后出现。你需要想办法等到你的服务器可以接受连接。

    为什么您看到 3 次尝试是因为这是底层 Apache HTTP 客户端的默认行为。

    您应该能够编写或重用某些实用程序来执行此操作。看看这段来自 Karate internals 的代码,寻找 waitForHttp 方法:

    https://github.com/intuit/karate/blob/develop/karate-core/src/main/java/com/intuit/karate/shell/Command.java#L112

    在我看来,执行此“等待”的最佳位置是在启动空手道套件的 JUnit/Java 代码中 - 您可能已经拥有启动 Spring Boot 的代码。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-27
      相关资源
      最近更新 更多