Skip to content
This repository has been archived by the owner on Sep 25, 2023. It is now read-only.

WebSocket session is not closed after all expected messages were received #75

Open
kuzznya opened this issue Aug 18, 2022 · 1 comment

Comments

@kuzznya
Copy link

kuzznya commented Aug 18, 2022

Existing WebSocket session is not closed after processing all expected messages with such configuration:

server.expect().withPath("/ws")
    .andUpgradeToWebSocket()
    .open()
    .expect("input")
    .andEmit(new OutputStreamMessage("output"))
    .once()
    .done()
    .always();

If my understanding is correct, session should close after "input" is received (if not, please correct me and I'll close the issue). This is not happening due to the check in io.fabric8.mockserver.internal.WebSocketSession::closeActiveSocketsIfApplicable:

public void closeActiveSocketsIfApplicable() {
        if (pendingMessages.isEmpty() && requestEvents.isEmpty() && httpRequestEvents.isEmpty()
          && sentWebSocketMessagesRequestEvents.isEmpty()) {
            activeSockets.forEach(ws -> ws.close(1000, "Closing..."));
        }
 }

i.e. requestEvents.isEmpty() - it is never empty when there were some expected messages because even after receiving expected message it still contains entry "input": <Empty queue>

@shawkins
Copy link
Contributor

shawkins commented May 23, 2023

This is still an issue, proactive closure support is inhibited.

Also related to this the mock server does not respect an incoming close message - it likely should echo that back to be well behaved. - that appeared to be the case behaviorally in a test, but upon checking the source it does indeed immediately echo.

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

No branches or pull requests

2 participants