[英]Karate 0.9.5.RC5 - 'retry until' function somehow does not respect my 'retry' configuration in karate-config.js
我有以下测试:
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 }
但这也不起作用。
也许你有一个提示为什么它不起作用或者我仍然想念什么?
感谢你的支持!
问题是retry until
建立HTTP连接后才出现。 您需要找到一种方法来等待您的服务器可以接受连接。
为什么您看到 3 次尝试是因为这是底层 Apache HTTP 客户端的默认行为。
您应该能够编写或重用某些实用程序来执行此操作。 看一下来自 Karate 内部的这段代码,寻找waitForHttp
方法:
在我看来,执行此“等待”的最佳位置是在启动空手道套件的 JUnit/Java 代码中 - 您可能已经拥有用于启动 Spring Boot 的代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.