Using multiple Akka Websocket Probes in test

Hello, I am trying to write a test which requires 2 websocket clients interacting with the system.
They need to send and receive messages one after the other.
For example:

  • First client 1 sends something and waits for a response
  • Then client 2 sends something and waits for a response
  • Then again client 1 sends something and waits for a response
  • and so on

I tried the following setup but the test failed with expected OnNext, found OnSubscribe

    "clients dont receive bet slip updates from other clients" in {
      val wsClient1 = WSProbe()
      val wsClient2 = WSProbe()

      def subscribeForBetSlip(wsClient: WSProbe, sessionId: SessionId): BetSlipId = {
        WS("/ws/api", wsClient.flow.via(wsClient2.flow)) ~> publicApi.publicApiRoute ~> check {
          val betSlipId: BetSlipId = setNextBetSlipId()

          val (requestId, request) = subscribeBetSlipRequest(sessionId)
          wsClient.expectMessage(expectedSubscribeBetSlipResponse(requestId, betSlipId))

      val sessionId1 = WS("/ws/api", wsClient1.flow) ~> publicApi.publicApiRoute ~> check {
      val sessionId2 = WS("/ws/api", wsClient2.flow) ~> publicApi.publicApiRoute ~> check {

      val betSlipId1 = subscribeForBetSlip(wsClient1, sessionId1)
      val betSlipId2 = subscribeForBetSlip(wsClient2, sessionId2)

      // ...    

It looks like I cannot split up the WS check blocks.
Does somebody know if its possible to write tests for such a scenario?

Hi David,

The RouteTest is built around blocking to make tests easier/cleaner to write, and doesn’t actually even start a real TCP server but bypasses some of the logic. To test two concurrent WebSocket connections like that I think you will have to actually start up a server and do real requests to it rather than use the testkit.