# WebSocket reconciliate wait for pending asynchronous wsListen checks

**URL:** <https://community.gatling.io/t/websocket-reconciliate-wait-for-pending-asynchronous-wslisten-checks/3801>\
**Category:** Gatling (Open-Source)\
**Created:** [June 30, 2017, 2:25pm UTC](https://community.gatling.io/t/websocket-reconciliate-wait-for-pending-asynchronous-wslisten-checks/3801 "2017-06-30T14:25:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bill\_Ruddock](https://avatars.discourse-cdn.com/v4/letter/b/d26b3c/32.png) [@Bill\_Ruddock](https://community.gatling.io/u/Bill_Ruddock)\
**Post date:** [June 30, 2017, 2:25pm UTC](https://community.gatling.io/t/websocket-reconciliate-wait-for-pending-asynchronous-wslisten-checks/3801/1 "2017-06-30T14:25:16Z")

</div>

I am using Gatling 2.2.5 and trying to achieve the following:

open a websocket  
send a HTTP POST request that triggers a server-side process that eventually sends a message to the websocket  
wait for the websocket response  
save a match from the websocket response

My original attempt for this has a race condition where the server-side process may complete before I start waiting for the websocket response (simplified snippet for demonstration):

.exec(ws(“Open websocket”).open("/"))  
.exec(  
http(“Trigger server-side process”)  
.post("/path/to/process")  
.check(status.is(201))  
)  
// race condition: WebSocket response may have already been sent here  
.exec(  
ws(“Await response”)  
.sendText("""{“event”:“ping”}""") // send an arbitrary message to enable setting a check  
.check(wsAwait.within(300 seconds).until(1).regex("""^(._“event”:“success”._)""").saveAs(“ws\_response”)  
)

I am now trying to achieve a flow which removes this race condition but the Gatling DSL does not seem to quite support what I want:

.exec(ws(“Open websocket”).open("/"))  
.exec(  
ws(“Listen non-blocking for response”)  
.sendText("""{“event”:“ping”}""") // send an arbitrary message to enable setting a check  
.check(wsListen.within(300 seconds).until(1).regex("""^(._“event”:“success”._)""").saveAs(“ws\_response”)  
.exec(  
http(“Trigger server-side process”)  
.post("/path/to/process")  
.check(status.is(201))  
)  
.exec(ws(“Reconciliate WebSocket and HTTP states”).reconciliate)

From experimentation and looking at the source code, it seems that reconciliate immediately cancels any pending checks, causing my script to fail. I want to wait until the websocket response has occurred and capture the saved variable into the session for future requests. I have tried making use of `asLongAs`, `during` et al but they do not seem to have access to the websocket state until reconciliate is called.

---

<div class="post-metadata">

**Author:** ![Alexander\_Mezhov](https://avatars.discourse-cdn.com/v4/letter/a/53a042/32.png) [@Alexander\_Mezhov](https://community.gatling.io/u/Alexander_Mezhov)\
**Post date:** [October 25, 2018, 12:23pm UTC](https://community.gatling.io/t/websocket-reconciliate-wait-for-pending-asynchronous-wslisten-checks/3801/2 "2018-10-25T12:23:37Z")

</div>

Does anyone know how to do it in v3.0?
