title: Jmeter websocket testing: how to use existing connection between thread groups
body: <p>Firstly I was using the <a href="https://bitbucket.org/pjtr/jmeter-websocket-samplers/src/master/" rel="nofollow noreferrer">JMeter WebSocket Samplers</a>. here is the order of operations that I needed to accomplish:</p>
  <ol>
  <li>Presenter connect</li>
  <li>Presenter create session; save session id</li>
  <li>Participant connect</li>
  <li>Participant subscribe to commands for saved session id</li>
  <li>Start latency test</li>
  </ol>
  <p>So based on the flow, I'm gonna need 2 connections to different endpoints (one is for presenter and the other is for participant).
  <a href="https://i.stack.imgur.com/oIvi8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/oIvi8.png" alt="enter image description here" /></a>
  I needed to make sure the first 4 steps are completed and both presenter and participant connect to the web socket successfully before I start the latency test. <br>
  I created 2 thread groups and connected to the endpoints for presenter and participant accordingly. My question is how do I manage to have the requests in the 2 thread groups executed in a specific order? Follow the order, I'd like to execute</p>
  <ol>
  <li><strong>Login-&gt;Connect-&gt;Subscribe</strong> in the Presenter thread group</li>
  <li><strong>Connect-&gt;Subscribe</strong> in the participant thread group</li>
  <li><strong>send</strong> request in the Presenter thread group</li>
  <li>The loop controller(which contains a WebSocket Single Read Sampler) in the Participant thread group.</li>
  </ol>
  <p>I tested it by putting the <strong>send</strong> request in a 3rd thread group, and then check <strong><strong>run thread groups consecutively</strong></strong> option in test plan. But the WebSocket single write sampler in the <strong>send</strong> request was not be able to use the existing connection anymore. (And there were 2 connections out there for presenter and participant) <br>
  <a href="https://i.stack.imgur.com/Q6PdX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Q6PdX.png" alt="enter image description here" /></a><br>
  And I am a little confused about the order of execution with my current setting. Looks like there were being executed randomly. The first 4 requests within participant thread group looks like being executed before any requests in the presenter thread group in the snapshot below, which messed up the data because the highlighted subscribe request in participant thread group was dependent on the session id that will be passed from request (<strong>WS-Subscribe-Presenter-/v1/create/session</strong>)in the presenter thread group. Due to the wrong order of execution, the session id that was passed to here was actually not the same session id that was created from the presenter request in this round of test run. It was actually still using the session Id that was created in the previous round of test run. <br>
  Note: I passed the session ID as a property such that the value can be passed between thread groups.</p>
  <pre><code>import groovy.json.JsonSlurper;
  
  def response = prev.getResponseDataAsString();
  String[] res = response.split();
  def json = new JsonSlurper().parseText(res[res.size() -1]);
  
  vars.put(&quot;sessionUUID&quot;, json.data.sessionUUID);
  props.put(&quot;sessionId&quot;, vars.get(&quot;sessionUUID&quot;));
  </code></pre>
  <p><a href="https://i.stack.imgur.com/cxR61.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cxR61.png" alt="enter image description here" /></a></p>