JMeter ignore specific types of responses in all Receive samplers (Websocket) - websocket

Is there a way for all Receive samplers to ignore specific responses in JMeter and wait for the one that we are interested?
To be more precise, we have created a jmx file that contains a large flow like a user would create on the browser. Each request sent is followed by a response, so we use a request handler followed by the corresponding receive handler for each call. And everything seems to work fine.
But there are cases that another kind of response may arrive, which is not the one we expect in our flow, but it is triggered by another independent mechanism. You can think of it like notifications sent to the user that is doing the flow and are independent of the flow itself, but theu are received in the channel (for us inside the websocket connection).
So we are trying to find a way to ignore a specific set of responses that may come while we are running the tests.
We firstly tried to add a While Controller in each receive sampler that checks if the content is of the desired type and if not loops again. But this solution has 3 disadvantages :
we have to add the sampler for the specific receive twice - one before the while element and one inside the element because we have to first extract the received data and while does not execute its contents before doing the while condition check
we have so many pairs of send-receive in our jmeter test script , that we have to add so many while controllers inside the script
since the received message may not be of the type we expect but another one that we want to ignore, then we cannot add a Response Assertion because it will fail if the notification arrives, so we have to verify the content indirect -> in the condition of the while loop
We use apache-jmeter-5.3.
So we are wondering if we could do another kind of configuration in order to avoid all these while loops.
It may be irrelevant to the solution, but we use websocket through "WebSocket Samplers by Peter Doornbosch".
Thanks

You don't have to, just amend your While Controller's condition to accept undefined variable as well
Sounds like a potential use case for using Module Controller to avoid code duplication
If you're getting the response you don't expect you can change the response body using JSR223 PostProcessor to the one you expect, example code
if (!prev.getResponseDataAsString().contains('foo')) {
prev.setResponseData('foo', 'UTF-8')
}

Related

JMETER Performance Testing - Dynamic Payload

While doing performance testing via JMETER, I encountered one usecase where the POST request call is taking the dynamic data from the website. So in that case when we run our script it fails as that data is no more available on the website.
Payload looks like given below. It is a POST CALL and the payload is changing everytime.
{"marketId":"U-16662943","price":{"up":98,"down":100,"dec":"1.98"},"side":"HOME","line":0,"selectionids":["W2-1"]}
Could anyone suggest how we can make this payload dynamic when we create a script in JMETER?
I can think of 3 possible options:
Duplicate data is not allowed. If this is the case you can use JMeter Functions like __Random(), __RandomString(), __counter() and so on
The data you're sending needs to be aligned with the data in the application somehow, in this case you can use JDBC PreProcessor in order to build a proper request body basing on the data from the application under test database
The data is present in previous response. In that case it's a matter of simple correlation, the dynamic values should be extracted from the previous response using suitable Post-Processors and variables needs to be sent instead of hard-coded parameters

How to implement a recursive call inside jmeter?

I need to simulate a test scenario where my application sends a request with 100s of queries. On the back-end, this request is broken down into requests containing a single query each. So a request from Jmeter with 100 queries will become 100 requests on the back-end. Now - the response from the back-end could either contain the requested data for each of those queries OR contain a unique queryID. Sending back a queryID is server's way of telling that this query is still running. For example, if Jmeter sends a request with 100 queries, it might get back data for 80 and 20 unique queryIDs. So my application under test makes a callback request with those 20 queryIDs every 15 seconds until it gets back the requested data or timeout.
Here is what I have implemented so far.
-main_request_with_100_queries
--XPath_extractor_to_extract_any_queryIDs_found
-if_controller_to_check_if_queryID_MatchNr_is_greater_than_0
--15_second_pause
--beanshell_preprocessor_to_create_the_request_body_with_all_queryIDs
--callback_request_with_queryIDs
What I want to implement is to have another XPath extractor for my callback_request and if any queryIDs are found, then go back to the if_controller
I'm trying to make this work by using a module_controller but so far no luck. Has anyone ever implemented something like this? Can anyone suggest some ideas?
You can use While Controller to keep making the request until there is a queryID in the response.
While Controller [ "${querid.present}"=="true" ]
HTTP Request
Pre Processor [to_create_the_request_body_with_all_queryIDs]
Post Processor [to check for query ID. if no query id - change querid.present to false ]
If possible, try to use Regular Expression Extractor. xpath is very slow and might affect your performance of the script. Check here for more details.
Creating modular test script in JMeter.

Using JMeter regex extraction in a loop controller

Right now, I have a Simple Controller set up to send a HTTP Request, and am extracting the request ID number from the response I get. This is working correctly. However, I want to send 3 such requests, and extract the request ID number from each, and may want to do even more in the future. I'm thinking the best way to set this up would be a loop controller, but I'm not sure how to extend my regex extractor that works for 1 HTTP request to work for multiple HTTP requests. The request ID number will be different each time, so I have to have a different variable for each, but I'm not sure how to make that happen. I was also looking at the ForEach loop, but I don't have any variables I am using as input, so I'm not sure that is the right choice for what I'm looking to do.

Ruby Sockets and parallel event handling

I'm writing a library that can interact with a socket server that transmits data as events to certain actions my library sends it.
I created an Actions module that formats the actions so that the server can read it. It also generates an action_id, because the events parser can identify it with the action that sent it. There are more than one event per action possible.
While I'm sending my action to the server, the event parser is still getting data from the server, so they work independent from each other (but then again they do work together: events response aggregator triggers the action callback).
In my model, I want to get a list of some resource from the server. The server sends its data one line at a time, but that's being handled by the events aggregator, so don't worry about that.
Okay, my problem:
In my model I am requesting the resources, but since the events are being parsed in another thread, I need to do a "infinite" loop that checks if the list is filled, and then break out to return it to the consumer of the model (e.g. my controller).
Is there another (better) way of doing this or am I on the right track? I would love your thoughts :)
Here is my story in code: https://gist.github.com/anonymous/8652934
Check out Ruby EventMachine.
It's designed to simplify this sort of reactor pattern application.
It depends on the implementation. In the code you provide you're not showing how actually the request and responses are processed.
If you know exactly the number of responses you're supposed to receive, in each one you could check if all are completed, then execute an specific action. e.g.
# suppose response_receiver is the method which receives the server response
def response_receiver data
#responses_list << data
if #response_list.size == #expected_size
# Execute some action
end
end

Difference between Event Aggregator, Commands and Request/Response

I'm trying to use Backbone.Marionette, and I read the docs on github about wreqr.
So, whats the difference between Event Aggregator, Commands and Request/Response. And when to use one or another?
They bascially all use messaging, and their difference is mainly semantic:
event aggregator: send a message when something happens. Code somewhere else might be listening for that message, but maybe not
request/response: have code send a request, and it will expect a response (e.g. send me refreshed data)
commands: code in one place commands code somewhere else to carry out an action. There usually isn't a return value.
I would like to add to David Sulc's answer.
Request/response is very different from event aggregator and commands. It is used for cases where one part your code requests something from another part of the code. A response would always be expected. Now lets see how event aggregator and commands are different.
Marionette's Event Aggregator allows you to implement publish-subscribe behaviour. Using the 'on' method you can subscribe to an event and bind an event to any object. You cannot implement this binding behaviour using commands. Also you can have multiple objects listening to any particular event. There may also be a case where no object is bound to or listening to any event.
Commands are specifically meant for performing some action in some other part of the code. There can only be 1 handler for a particular command, unlike events where you can have multiple listeners.
So to summarize, the use cases for each would be:
1) Request/Response: When you need some response from another part of the code.
2) Event Aggregator: When you want to bind objects to events
3) Commands: You just want some other part of your code to perform a task.

Resources