在GenericContainer
类中,它存在一个方法waitingFor
,它等待状态码200
作为来自服务器的响应。
我在容器中运行 Web 应用程序并0.0.0.0
用作主机而不是localhost
. 当我尝试运行时sbt test
,我有以下超时:
[sweetsoft/sapmock:latest] - Could not start container
org.testcontainers.containers.ContainerLaunchException: Timed out waiting for container port to open (localhost ports: [8080] should be listening)
我正在使用测试容器如下:
final class MessageSpec extends BddSpec
with ForAllTestContainer
with BeforeAndAfterAll {
override val container = FixedHostPortGenericContainer("sweetsoft/sapmock",
waitStrategy = Wait.forHttp("/"),
exposedHostPort = 8080,
exposedContainerPort = 8080,
)
override def beforeAll(): Unit = {
}
feature("Process incoming messages") {
info("As a user, I want that incoming messages is going to process appropriately.")
info("A message should contain the following properties: `sap_id`, `sap_event`, `payload`")
当我删除waitStrategy = Wait.forHttp("/")
时,它可以正常工作,但waitStrategy = Wait.forHttp("/")
会进入超时。
如何告诉Testcontainer
听0.0.0.0
而不是听localhost
?我在这里描述了 localhost 的问题:为什么客户端无法连接到 localhost:8080?