简体   繁体   English

空手道 0.9.5.RC5 - “重试直到”函数以某种方式不尊重我在 karate-config.js 中的“重试”配置

[英]Karate 0.9.5.RC5 - 'retry until' function somehow does not respect my 'retry' configuration in karate-config.js

I have following test:我有以下测试:

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"

and the following karate-config.js和以下 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;
}

and the following error in the console after executing the tests with the maven-failsafe-plugin:使用 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
...

Before the tests start, I boot up my Spring Boot application and this takes some time (~5-7 seconds) and I know that the test does not succeed because the Sprint Boot app has not yet started.在测试开始之前,我启动了我的 Spring Boot 应用程序,这需要一些时间(约 5-7 秒),我知道测试没有成功,因为 Sprint Boot 应用程序尚未启动。

That's why I've tried to use this retry until feature of Karate to make sure it retries after some intervals.这就是为什么我尝试使用此retry until空手道的功能来确保它在一些时间间隔后重试。

But it seems that the retry config is not respected according to the console output.但是根据控制台输出似乎不遵守retry配置。 It seems so that it always only try 3 times...似乎它总是只尝试 3 次......

I have also tried to set the retry config in the test file itself like in the Karate docs with:我还尝试在测试文件本身中设置retry配置,就像在空手道文档中一样:

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

but this also did not work.但这也不起作用。

Maybe you have a hint why it does not work or do I still miss something?也许你有一个提示为什么它不起作用或者我仍然想念什么?

Thanks for support!感谢你的支持!

The problem is retry until comes into the picture only after the HTTP connection has been established.问题是retry until建立HTTP连接后才出现。 You need to figure out a way to wait until your server can accept connections.您需要找到一种方法来等待您的服务器可以接受连接。

Why you see 3 attempts is because that is the default behavior of the underlying Apache HTTP client.为什么您看到 3 次尝试是因为这是底层 Apache HTTP 客户端的默认行为。

You should be able to write or re-use some utility to do this.您应该能够编写或重用某些实用程序来执行此操作。 Take a look at this code from Karate internals, look for the waitForHttp method:看一下来自 Karate 内部的这段代码,寻找waitForHttp方法:

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

And in my opinion, the best place to do this "wait" is in the JUnit / Java code that kicks off the Karate suite - which you probably already have for starting Spring Boot.在我看来,执行此“等待”的最佳位置是在启动空手道套件的 JUnit/Java 代码中 - 您可能已经拥有用于启动 Spring Boot 的代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM