java - 空手道 0.9.5.RC5 -“重试直到”功能不知何故不尊重我在 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 internals 中的这段代码,寻找waitForHttp
方法:
在我看来,执行此“等待”的最佳位置是在启动空手道套件的 JUnit / Java 代码中 - 您可能已经拥有用于启动 Spring Boot 的套件。
推荐阅读
- javascript - 按下按钮并更改页面时执行完整的js功能
- controls - 有没有办法将我的 subreddit 隐藏在他们必须填写才能获得访问权限的调查后面?
- javascript - 通过算术运算符拆分字符串
- ios - MPMusicPlayerControllerNowPlayingItemDidChange 是不可预测的
- ansible - ansible 中的嵌套循环 - Vcloud director
- python - Pyinstaller 和 PyQt5 macOS Mojave 兼容性问题
- ios - 使用一个浮动标题查看多个部分
- c# - 重定向自定义用户控件中的按钮单击时的设计器错误
- android - Firebase 存储 - 检索和显示图像
- amazon-web-services - 如何在不显示我的 s3 链接而是保持烧瓶 url 路由的情况下路由到我的 S3 实例?