自动配置的Wiremock-集成测试类中的第一个测试因套接字读取超时而失败

时间:2019-07-17 14:04:21

标签: rest-assured wiremock

当集成测试中的第一个测试突然开始失败并返回以下错误信息时,我有一个Wiremock @AutoConfigureWiremock + RestAssured的奇怪错误:

1 expectation failed.
Expected status code <200> doesn't match actual status code <503>.

日志显示FeignException

[NODE=host] [ENV=test] [SRC=UNDEFINED] [TRACE=] [SPAN=] [2019-07-17T08:37:50.854Z] [ERROR] [MSG=[http-nio-8080-exec-2] c.f.o.f.s.SomeService - Timeout error while connecting to foo service. Merchant reference: xxx, transaction id: xxx, message: Read timed out executing POST http://localhost:10866/xxx/send feign.RetryableException: Read timed out executing POST http://localhost:10866/xxx/send
    at feign.FeignException.errorExecuting(FeignException.java:128)
    at feign.SynchronousMethodHandler.executeAndDecode(SynchronousMethodHandler.java:113)
...
Caused by: java.net.SocketTimeoutException: Read timed out
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)

我在日志中看到Wiremock与存根文件进行匹配之前发生了异常,并且匹配成功。

这仅在此类的第一次测试中发生;当我重命名测试以更改执行顺序时,在其他任何测试之前执行的另一个测试将因相同的错误而失败。如果我单独运行此测试,则该测试通过。如果我仅运行此测试类,则它们也将通过。当我在应用程序中运行所有测试时,就会出现问题。

我注意到执行此失败的测试会花费更多的时间,例如大约3秒或更短的时间。

我认为是因为那时候Wiremock服务器尚未准备就绪。我已经看到有关此提议的一些解决方案的帖子,但没有一个对我有用:

https://www.bountysource.com/issues/1841251-put-stub-seems-to-fail-if-test-method-runs-too-fast

还在Wiremock中看到了一个错误报告:

https://github.com/tomakehurst/wiremock/issues/97

0 个答案:

没有答案