# Websocket heartbeats as an asynchronous task

**URL:** https://community.gatling.io/t/websocket-heartbeats-as-an-asynchronous-task/4703
**Category:** Gatling (Open-Source)
**Created:** [December 12, 2018, 3:52pm UTC](https://community.gatling.io/t/websocket-heartbeats-as-an-asynchronous-task/4703 "2018-12-12T15:52:05Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Thomas](https://avatars.discourse-cdn.com/v4/letter/t/e36b37/32.png) [@Thomas](https://community.gatling.io/u/Thomas)
#### Post date: [December 12, 2018, 3:52pm UTC](https://community.gatling.io/t/websocket-heartbeats-as-an-asynchronous-task/4703/1 "2018-12-12T15:52:05Z")

</div>

Hello,

In my Gatling scenario when a user logs in, a websocket connection opens.

To maintain the connection I have to ping the server every X ms, otherwise the connection crash.

My need is to execute a loop where the heartbeat between websocket client and server is executed at the same time as the scenario.  
Is there a way to execute some action as an asynchronous task inside a Gatling scenario with Gatling DSL or Scala ?

Thank you in advance.

Thomas.

---

<div class="post-metadata">

### Author: ![slandelle](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/slandelle/32/4_2.png) [@slandelle](https://community.gatling.io/u/slandelle)
#### Post date: [December 12, 2018, 4:18pm UTC](https://community.gatling.io/t/websocket-heartbeats-as-an-asynchronous-task/4703/2 "2018-12-12T16:18:50Z")

</div>

Nope, you’ll have to make those messages parts of your flow.

---

<div class="post-metadata">

### Author: ![Thomas](https://avatars.discourse-cdn.com/v4/letter/t/e36b37/32.png) [@Thomas](https://community.gatling.io/u/Thomas)
#### Post date: [December 12, 2018, 4:35pm UTC](https://community.gatling.io/t/websocket-heartbeats-as-an-asynchronous-task/4703/3 "2018-12-12T16:35:52Z")

</div>

On the website I want to test, the heartbeat is running in the background until the user disconnected.

So, I want to simulate that in my Gatling scenario and this translate into a loop that run until the user logs out. The problem is that block the flow of the scenario...

There is no way to simulate this behaviour ? Even with some Scala code ?

I don't know if my explanation are clear...

Thomas

---

<div class="post-metadata">

### Author: ![Katerina\_Stepanova](https://avatars.discourse-cdn.com/v4/letter/k/54ee81/32.png) [@Katerina\_Stepanova](https://community.gatling.io/u/Katerina_Stepanova)
#### Post date: [December 13, 2018, 11:05am UTC](https://community.gatling.io/t/websocket-heartbeats-as-an-asynchronous-task/4703/4 "2018-12-13T11:05:51Z")

</div>

I had the same problem. I did not find the way to integrate heartbeats into the main test flow unfortunately.  
The only way i found to deal with it was creating my own version of wsActor, which sent a heartbeat on every heartbeat coming from server side. But it was in Gatling 2.3. I did not have time to migrate to Gatling 3 yet, but it might be possible to implement something similar there.

---

<div class="post-metadata">

### Author: ![saket\_kothari](https://avatars.discourse-cdn.com/v4/letter/s/6bbea6/32.png) [@saket\_kothari](https://community.gatling.io/u/saket_kothari)
#### Post date: [December 13, 2018, 3:25pm UTC](https://community.gatling.io/t/websocket-heartbeats-as-an-asynchronous-task/4703/5 "2018-12-13T15:25:30Z")

</div>

Hi Stephane,  
Can you please give an example of how we can do this?

In gatling 2.3.1 ping/pong was taken care by the framework.

Thanks in advance.
