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.sendMessage(request)
wsClient.expectMessage(expectedSubscribeBetSlipResponse(requestId, betSlipId))
betSlipId
}
}
val sessionId1 = WS("/ws/api", wsClient1.flow) ~> publicApi.publicApiRoute ~> check {
sessionCreated(wsClient1)
}
val sessionId2 = WS("/ws/api", wsClient2.flow) ~> publicApi.publicApiRoute ~> check {
sessionCreated(wsClient2)
}
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?