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.58k stars 1.07k forks source link

Times.once returns more than once #1826

Open maestrokame opened 8 months ago

maestrokame commented 8 months ago

Describe the issue I mocked a request with Times.once() but the response is returned to more than one request.

What you are trying to do I'm trying to mock an API that works like a queue. Multiple clients are polling that API waiting for any data to unconsume. I'm trying to use Times.once() so that only to one of the clients can get the mocked response.

MockServer version 5.14.0

To Reproduce A repository with minimal reproduceable. Please try a couple of times if it does not reproduce. https://github.com/maestrokame/reproduce-mockserver-issue-with-once/tree/main

  1. How you are running MockServer (i.e maven plugin, docker, etc)

    MockServerClient mockServer = ClientAndServer.startClientAndServer(3000);
  2. Code you used to create expectations

    mockServer.when(request("/output/.*").withMethod("GET"), Times.once())
        .respond(response()
                .withStatusCode(200)
                .withBody("OK"));
  3. What error you saw No error. Just observed more than one API client getting the same response.

Expected behaviour Return the response only to one of the clients

MockServer Log log

bonati-s commented 4 months ago

Linked to https://github.com/mock-server/mockserver/issues/1834