mock-server / mockserver

MockServer enables easy mocking of any system you integrate with via HTTP or HTTPS with clients written in Java, JavaScript and Ruby. MockServer also includes a proxy that introspects all proxied traffic including encrypted SSL traffic and supports Port Forwarding, Web Proxying (i.e. HTTP proxy), HTTPS Tunneling Proxying (using HTTP CONNECT) and SOCKS Proxying (i.e. dynamic port forwarding).
http://mock-server.com
Apache License 2.0
4.61k stars 1.08k forks source link

Mockserver randomly times out on Mac with M1 max chip #1736

Open pengyu-zhao opened 1 year ago

pengyu-zhao commented 1 year ago

Describe the issue I recently switched to a m1 max macbook and i found that the startup of mockserver often timed out randomly. Occasionally after a successful startup and tests are running, but the response from mockserver also timed out. It happens no matter how many mock servers i am trying to run, so it's really like rolling dices running tests now. Sometimes i have to restart tests 15 - 20 times to get the tests running if i have multiple services to mock, because each one of them could timeout randomly. On my other intel-based macbook, this was not an issue.

What you are trying to do I hope someone can help me to figure out why this is happening, and then figure out what are the potential solutions (either short term or long term ones)

MockServer version 5.15.0

To Reproduce Steps to reproduce the issue:

I made a simple example where i can reproduce the issue:

class MockserverIssueReproduceTests {

    private static final String MOCKSERVER = "mockserver/mockserver:mockserver-" + MockServerClient.class.getPackage().getImplementationVersion();

    private static final MockServerContainer serviceContainer1 = new MockServerContainer(
        DockerImageName.parse(MOCKSERVER)
    );

    private static final MockServerContainer serviceContainer2 = new MockServerContainer(
        DockerImageName.parse(MOCKSERVER)
    );

    private static final MockServerContainer serviceContainer3 = new MockServerContainer(
        DockerImageName.parse(MOCKSERVER)
    );

    private static final MockServerContainer serviceContainer4 = new MockServerContainer(
        DockerImageName.parse(MOCKSERVER)
    );

    private static final MockServerContainer serviceContainer5 = new MockServerContainer(
        DockerImageName.parse(MOCKSERVER)
    );

    static {
        serviceContainer1.start();
        serviceContainer1.waitingFor(Wait.forHealthcheck());

        serviceContainer2.start();
        serviceContainer2.waitingFor(Wait.forHealthcheck());

        serviceContainer3.start();
        serviceContainer3.waitingFor(Wait.forHealthcheck());

        serviceContainer4.start();
        serviceContainer4.waitingFor(Wait.forHealthcheck());

        serviceContainer5.start();
        serviceContainer5.waitingFor(Wait.forHealthcheck());
    }

    @Test
    public void serviceContainerStarts() {
        System.out.println("Mockservers started");
    }
}

I simply run this test, any mockserver would time out randomly. The more mockservers I start, the easier it is to hit the timeout issue.

MockServer Log

2023-05-01 23:19:02,316 INFO  [main] o.t.c.GenericContainer: Creating container for image: testcontainers/ryuk:0.3.4
2023-05-01 23:19:02,777 INFO  [main] o.t.c.GenericContainer: Container testcontainers/ryuk:0.3.4 is starting: 3be8db5f07f0ce8dc71f9869e3dde7f8eb57ddae7ad46e0de6677da5ec119f48
2023-05-01 23:19:02,994 INFO  [main] o.t.c.GenericContainer: Container testcontainers/ryuk:0.3.4 started in PT0.735841S
2023-05-01 23:19:02,999 INFO  [main] o.t.c.GenericContainer: Creating container for image: mockserver/mockserver:mockserver-5.15.0
2023-05-01 23:19:03,021 INFO  [main] o.t.c.GenericContainer: Container mockserver/mockserver:mockserver-5.15.0 is starting: 9aa37001d088bac8ab2d88e5fea96fcdd4a807e2bc0ae103106102e1d9cc8964
2023-05-01 23:19:09,287 INFO  [main] o.t.c.GenericContainer: Container mockserver/mockserver:mockserver-5.15.0 started in PT6.287689S
2023-05-01 23:19:09,288 INFO  [main] o.t.c.GenericContainer: Creating container for image: mockserver/mockserver:mockserver-5.15.0
2023-05-01 23:19:09,314 INFO  [main] o.t.c.GenericContainer: Container mockserver/mockserver:mockserver-5.15.0 is starting: a3788f6007d26a7d0f720eaa8e0362c1d7cdc9e14d54bf5664d984b9e33f21e9
2023-05-01 23:19:15,377 INFO  [main] o.t.c.GenericContainer: Container mockserver/mockserver:mockserver-5.15.0 started in PT6.089225S
2023-05-01 23:19:15,378 INFO  [main] o.t.c.GenericContainer: Creating container for image: mockserver/mockserver:mockserver-5.15.0
2023-05-01 23:19:15,406 INFO  [main] o.t.c.GenericContainer: Container mockserver/mockserver:mockserver-5.15.0 is starting: 90664193f8efc4d0b00b93aaca93971fea9dea18265475c8fb20fa3f834796d9
2023-05-01 23:20:15,597 ERROR [main] o.t.c.GenericContainer: Could not start container
org.testcontainers.containers.ContainerLaunchException: Timed out waiting for URL to be accessible (http://localhost:53744/mockserver/status should return HTTP [200])
    at org.testcontainers.containers.wait.strategy.HttpWaitStrategy.waitUntilReady(HttpWaitStrategy.java:318)
    at org.testcontainers.containers.wait.strategy.AbstractWaitStrategy.waitUntilReady(AbstractWaitStrategy.java:52)
    at org.testcontainers.containers.GenericContainer.waitUntilContainerStarted(GenericContainer.java:953)
    at org.testcontainers.containers.GenericContainer.tryStart(GenericContainer.java:485)
    at org.testcontainers.containers.GenericContainer.lambda$doStart$0(GenericContainer.java:344)
    at org.rnorth.ducttape.unreliables.Unreliables.retryUntilSuccess(Unreliables.java:81)
    at org.testcontainers.containers.GenericContainer.doStart(GenericContainer.java:334)
    at org.testcontainers.containers.GenericContainer.start(GenericContainer.java:322)
    at issue.reproduce.mockserver.MockserverIssueReproduceTests.<clinit>(MockserverIssueReproduceTests.java:40)
    at java.base/java.lang.Class.forName0(Native Method)
    at java.base/java.lang.Class.forName(Class.java:315)
    at com.intellij.junit5.JUnit5TestRunnerUtil.loadMethodByReflection(JUnit5TestRunnerUtil.java:126)
    at com.intellij.junit5.JUnit5TestRunnerUtil.buildRequest(JUnit5TestRunnerUtil.java:102)
    at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:43)
    at com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38)
    at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11)
    at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35)
    at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:232)
    at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:55)
2023-05-01 23:20:15,639 ERROR [main] o.t.c.GenericContainer: Log output from the failed container:
2023-05-02 03:19:17 5.15.0 INFO using environment variables:

  [

  ]

 and system properties:

  [
    mockserver.propertyFile=/config/mockserver.properties
  ]

 and command line options:

  [
    serverPort=1080
  ]

2023-05-02 03:19:19 5.15.0 INFO logger level is INFO, change using:
 - 'ConfigurationProperties.logLevel(String level)' in Java code,
 - '-logLevel' command line argument,
 - 'mockserver.logLevel' JVM system property or,
 - 'mockserver.logLevel' property value in 'mockserver.properties' 
2023-05-02 03:19:19 5.15.0 INFO 1080 started on port: 1080 

Exception in thread "main" java.lang.ExceptionInInitializerError
    at java.base/java.lang.Class.forName0(Native Method)
    at java.base/java.lang.Class.forName(Class.java:315)
    at com.intellij.junit5.JUnit5TestRunnerUtil.loadMethodByReflection(JUnit5TestRunnerUtil.java:126)
    at com.intellij.junit5.JUnit5TestRunnerUtil.buildRequest(JUnit5TestRunnerUtil.java:102)
    at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:43)
    at com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38)
    at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11)
    at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35)
    at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:232)
    at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:55)
Caused by: org.testcontainers.containers.ContainerLaunchException: Container startup failed
    at org.testcontainers.containers.GenericContainer.doStart(GenericContainer.java:349)
    at org.testcontainers.containers.GenericContainer.start(GenericContainer.java:322)
    at issue.reproduce.mockserver.MockserverIssueReproduceTests.<clinit>(MockserverIssueReproduceTests.java:40)
    ... 10 more
Caused by: org.rnorth.ducttape.RetryCountExceededException: Retry limit hit with exception
    at org.rnorth.ducttape.unreliables.Unreliables.retryUntilSuccess(Unreliables.java:88)
    at org.testcontainers.containers.GenericContainer.doStart(GenericContainer.java:334)
    ... 12 more
Caused by: org.testcontainers.containers.ContainerLaunchException: Could not create/start container
    at org.testcontainers.containers.GenericContainer.tryStart(GenericContainer.java:542)
    at org.testcontainers.containers.GenericContainer.lambda$doStart$0(GenericContainer.java:344)
    at org.rnorth.ducttape.unreliables.Unreliables.retryUntilSuccess(Unreliables.java:81)
    ... 13 more
Caused by: org.testcontainers.containers.ContainerLaunchException: Timed out waiting for URL to be accessible (http://localhost:53744/mockserver/status should return HTTP [200])
    at org.testcontainers.containers.wait.strategy.HttpWaitStrategy.waitUntilReady(HttpWaitStrategy.java:318)
    at org.testcontainers.containers.wait.strategy.AbstractWaitStrategy.waitUntilReady(AbstractWaitStrategy.java:52)
    at org.testcontainers.containers.GenericContainer.waitUntilContainerStarted(GenericContainer.java:953)
    at org.testcontainers.containers.GenericContainer.tryStart(GenericContainer.java:485)
    ... 15 more
GerMoranBYON commented 1 year ago

This is a dupe of #1568

There is an open PR #1665 to build ARM images which may resolve the compatible with M1 (arm64_v8) Local workaround would be to pull the repo and build locally, reference that local image (assuming you are using mac m1 as dev env).

pengyu-zhao commented 1 year ago

Thanks @GerMoranOverstock. I'll try it out