Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mock Server doesn't start after updating to 5.11.0 #2984

Closed
nikos912000 opened this issue Jul 9, 2020 · 4 comments · Fixed by #3437
Closed

Mock Server doesn't start after updating to 5.11.0 #2984

nikos912000 opened this issue Jul 9, 2020 · 4 comments · Fixed by #3437

Comments

@nikos912000
Copy link

Hi folks!

I'm raising this here although it may be related to the Mock Server. We're having issues when updating to the latest version of the Mock Server and its Java client (5.11.0) with Testcontainers.

The Problem

We use Testcontainer's MockServerContainer which starts the jamesdbloom/mockserver container, something like:

@Container
static MockServerContainer mockServerContainer = new MockServerContainer("5.11.0"));

The container doesn't seem to start and the build/tests time out waiting for it:

2020-07-09T17:16:36.590+0100 ERROR  [main] ?.11.0] - Could not start container org.testcontainers.containers.ContainerLaunchException: Timed out waiting for container port to open (localhost ports: [33023] should be listening)

This is working fine in 5.10.0.

Potential Solution

The bit that seems to cause the issue is the addExposedPorts call in the MockServerContainer. I created a custom class with the same logic but without it and solves the problem.
I've also tested it in 5.10.0 and works fine. Is this a reasonable workaround and is there any reason why this call was/is needed?

Thanks :)

@vcvitaly
Copy link
Contributor

I can reproduce it, the reason it fails is:

OCI runtime exec failed: exec failed: container_linux.go:349: starting container process caused "exec: \"/bin/sh\": stat /bin/sh: no such file or directory": unknown

On startup Testcontainers runs a command in container to verify the status and starting 5.11.0 Mockserver image doesn't contain /bin/sh.

It's also a good question why nothing is logged in InternalCommandPortListeningCheck in case of such error.

@vcvitaly
Copy link
Contributor

vcvitaly commented Jul 16, 2020

@bsideup I described the issue in the PR, could you please advice if such improvement would make sense? It's a rare case.

A simple test to reproduce:

public class SomeTest {
    @Test
    public void test_5_11() {
        MockServerContainer mockServerContainer = new MockServerContainer("5.11.0").withStartupTimeout(Duration.ofSeconds(10));
        mockServerContainer.start();
        System.out.println(mockServerContainer);
    }

    @Test
    public void test_5_10() {
        MockServerContainer mockServerContainer = new MockServerContainer("5.10.0");
        mockServerContainer.start();
        System.out.println(mockServerContainer);
    }
}

@nikos912000 I'm not sure, but there seems to be a problem with 5.11.0 image, trying to connect to container causes:
OCI runtime exec failed: exec failed: container_linux.go:349: starting container process caused "exec: \"/bin/sh\": stat /bin/sh: no such file or directory": unknown

@nikos912000
Copy link
Author

Thanks @vcvitaly and apologies for not coming back.

I had a look at this today and the issue has to do with the wait strategy. The default wait strategy worked until 5.10.0 but for 5.11.0 I needed to provide a WaitStrategy that's based on an HTTP endpoint.

@Container
static MockServerContainer mockServerContainer = new MockServerContainer("5.11.0")
    .withEnv("MOCKSERVER_LIVENESS_HTTP_GET_PATH", "/health")
    .waitingFor(Wait.forHttp("/health").forStatusCode(200));

As regards the MOCKSERVER_LIVENESS_HTTP_GET_PATH, by default Mock Server exposes a PUT health/live check and so I provided a custom GET one, as explained in the docs.

With that it now works ok.

lanwen added a commit to lanwen/testcontainers-java that referenced this issue Nov 7, 2020
fixes testcontainers#2984, testcontainers#2710

in mock-server/mockserver@9f27af0 mockserver introduced a GET http healthcheck (what was released in 5.9.0) and since 5.11.0 uses distroless image, with the default wait strategy, we hit into testcontainers#3317

As the 5.11.0+ is actually a smaller image, more secure and 5.9.0 was released almost a year ago (which means users with 5.9.0+ versions would be able to update testcontainers without changes), I think worth bumping the base version.

For the users on old versions the old behaviour could be set with the default waiting strategy back
`.waitingFor(Wait.defaultWaitStrategy())`.

This PR also brings two small changes to be complete - mockserver official image now is `mockserver/mockserver` (but I added previous as a compatible).
And added small note to the docs regarding matched version of a client, as anyway had to change docs after test adjustments (wasn't able to test properly with rule in the same class as old version).
@stale
Copy link

stale bot commented Nov 21, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you believe this is a mistake, please reply to this comment to keep it open. If there isn't one already, a PR to fix or at least reproduce the problem in a test case will always help us get back on track to tackle this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants