【发布时间】: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