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

Getting 404 and dashboard shows client {clientId} has closed web socket connection #1889

Open
anu-jose opened this issue Jul 22, 2024 · 2 comments

Comments

@anu-jose
Copy link

anu-jose commented Jul 22, 2024

Describe the issue
Getting 404 because client {clientId} has closed web socket connection

What you are trying to do
I am trying to setup a mockserver that would test some of payment flows. Our software will send a payment request to the mockserver, and based on the paymentId and payment amount mockserver should either return status=AUTHORIZED or status=DENIED.

Using 'mockserver-client-java' with java code to setup the expectations.

Steps:

  1. In test, I set expectation to stay live for 30 minutes, send payment.and verified that the response is correct.
  2. Checked in the mockserver dashboard that the expectation is active.
  3. Now since the expectation is live, I send another payment with valid params and I expect to get a 200 again. But I am getting a 404. The dashboard now shows a warning
    client {clientId} not found for request {...}client registry only contains
    and
07-22 19:08:07.357 NO_MATCH_RESPONSE         	no expectation for:	
{...}
returning response:	
{...}
07-22 19:08:07.357 EXPECTATION_NOT_MATCHED   	request:	
{...}
didn't match expectation:	
{...}
because:	
...
07-22 19:08:07.357 RECEIVED_REQUEST          	received request:	
{...}
07-22 19:07:59.734 EXPECTATION_RESPONSE      	
07-22 19:07:59.734 EXPECTATION_RESPONSE      	returning response:	
{...}
for request:	
{...}
for action:	
{...}
from expectation:	"4f552174-8e92-42aa-b536-4878484eebf5"
07-22 19:07:59.734 WARN                      	returning	
{...}
because client {clientId} has closed web socket connection
07-22 19:07:59.733 EXPECTATION_MATCHED       	request:	
{...}
matched expectation:	
{...}
07-22 19:07:59.733 RECEIVED_REQUEST          	received request:	
{...}

I am not sure if this is a bug or if I missed some steps
MockServer version
5.15.0

To Reproduce
Steps to reproduce the issue:

  1. Setup an expectation that would be live for 30 mins.

  2. In a different test, send a request that matches the request in the expectation. Verify that it returns 404.

  3. How you are running MockServer (i.e maven plugin, docker, etc) -> on a container in EKS

  4. Code you used to create expectations

 public void paymentFirstTry() {
    client
        .when(getRequest("1.37"), unlimited(), TimeToLive. exactly(MINUTES, 30L), -1)
        .respond(response);
  }
@Test
public void test(){
// fundingClientMockServer.paymentFirstTry();
    ValidatableResponse response = postPayment(paymentId, "1.37");
    verifyResponse(response, paymentId);
}

If I uncomment first line, it works fine. But after running the test once, the expectation is LIVE for 30 minutes, so I shouldn't have to run it again, right?
8. What error you saw

Expected behaviour
As long as the expectation is LIVE, I expected to get a 200.

MockServer Log
Log output, as INFO level (or lower)

returning	
{...}
because client 61fb84d8-7ae7-4aa3-99d5-0ed500f47c6f has closed web socket connection
@anu-jose anu-jose changed the title Getting 404 and dashboard shows client 61fb84d8-7ae7-4aa3-99d5-0ed500f47c6f has closed web socket connection Getting 404 and dashboard shows client {clientId} has closed web socket connection Jul 22, 2024
@veijov
Copy link

veijov commented Jul 31, 2024

I ran into very same problem but in a different kind of setup.

What you are trying to do
I am using MockServer as browser proxy to simulate some third party integrations:

  1. Selenium controlled browser use MockServer (as a Docker container) as a proxy
  2. Test classes control Selenium
  3. Test classes connects to MockServer using MockServerClient and creates needed expectations

MockServer version
5.12.0 (because, currently still using java 8)

To Reproduce

  1. Run MockServer Docker Container
  2. Configure browser to use MockServer as a proxy
  3. Test class: Create MockServerClient (new MockServerClient("localhost", 1080)) and create expection(s)
  4. Test class: Navigate to web page that match to expectation using Selenium controlled browser
  5. Result: HTTP 404 not found, because client {clientId} has closed web socket connection

Expected behaviour
Expectation

Workaround: Running MockServer via a JUnit 4 @rule (!!)

@veijov
Copy link

veijov commented Jul 31, 2024

I think I found the reason - programmatic expectations (callbacks).

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

No branches or pull requests

2 participants