WebSocket matching API - different order of responses

Hello,

Im using Websocket protocol during my simulation, and for one message I can got several responses. Only two of them are necessary for me to gather some data and the question is how can I handle such scenario when those two important responses can arrive in different order? For exmaple

WS - Send some message
Server respond - non-important response
Server respond - important response 1
Server respond - important response 2

WS - Send some message
Server respond - non-important response
Server respond - important response 2
Server respond - important response 1

Example of current implementation (hardcoded for specific order of responses)

.doWhile(checkForProperMessage).on(
        pause(Duration.ofMillis(50))
          .exec(sendMessage
            .await(6).on(Checks.firstResponse)
            .await(6).on(Checks.secondResponse)
          ))

Implementation of checks:

    ws.checkTextMessage("First Response")
      .matching(regex("\\d.+\"SOME_REGEX\".+"))
      .check(regex("SOME_REGEX").captureGroups(2).saveAs("some_session_id));

If response will match my regex I have to store some part of the message cuz there is provided information about the delay which I have to use before sending next message to give user some time to do some action during WebSocket connection

    ws.checkTextMessage("Second Response")
      .matching(regex("SOME_REGEX)
      .check(regex("(.+\"imageQuality\":\")(IMAGE_QUALITY_\\w+)(\".+)")
        .captureGroups(2).saveAs(IMAGE_QUALITY_REQUEST_GROUP_KEY));

And here if response will match my regex I have to store some part of response to validate if doWhile step is satisfied or not

Both messages can appear at different order. Is there any way to handle such case?

BR
Mateusz

I don’t think that’s possible atm.

I think this would require:

  • being able to set a check without sending a message first
  • being able to buffer inbound messages to cope with messages that would be received just before setting such check

so, at the moment it’s possible to write some checks with regex like .+ and store all of them in Session API. After that create custom method to parse all stored responses - which I believe will be not very convenient in context of performance

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.