JMeter won't follow redirects when cache is enabled - jmeter

I'm having a bit of a strange problem with JMeter that almost seems like a bug. I'm running version 5.1.1 r1855137.
I have a standard HTTP Request Sampler and an HTTP Cache Manager. The HTTP request is set to Follow Redirects. It is also set to Use KeepAlive, and to download all embedded resources with up to 6 parallel downloads. The Cache Manager is set to Clear cache each iteration, and to use Cache-Control/Expires headers. A limit of 5000 elements in the cache is set.
I've create a thread group with a loop controller in it. The HTTP request sampler is inside this thread group and loop. The page in the initial request returns a HTTP/1.1 302 Found. I also notice that in the headers there is Cache-Control: private, s-maxage=0. The first time through the loop, JMeter follows the redirect and downloads all of the resources. Subsequent assertions are fine. The second time through, JMeter only sends the request for the initial page and then does not follow the redirect. Following assertions fail because objects are missing that I'm expecting to find in sub requests.
I know this is a cache issue, because if I remove the Loop Controller in the thread group, and instead make the thread group loop, the problem will go away IF I leave the option to "Clear cache each iteration," checked on the Cache Manager. If I turn this option off, the same problem occurs when the thread group loops.
Does anybody know why JMeter does not follow 302 redirects when the cache manager is active? Is the website not following proper protocol by providing a Cache-Control header of private, s-maxage=0?

Looking at JMeter source code, JMeter caches 2xx and 304s. And GET requests. See: https://github.com/apache/jmeter/blob/master/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/control/CacheManager.java#L355
So it should not be caching your 302s. Have you tried using Redirect Automatically option to see if that works correctly:

Related

Jmeter cache manager not working on localhost

I am using Jemeter 5.4.1 and I have an HttpRequest sampler pointing to localhost. I also have the Number of threads set to 1
Loop Count to 100
When I add cache manager, the execution stops after only 1 sample run even though I have set the loop count to 100. But when I turn off the cache manage, the loop works.
It's hard to say what's wrong with your configuration without seeing the full response, how embedded resources are being returned exactly and what are response headers
Try unticking Use Cache-Control/Expires header
Additionally, if the "Use Cache-Control/Expires header" option is selected, then the Cache-Control/Expires value is checked against the current time. If the request is a GET request, and the timestamp is in the future, then the sampler returns immediately, without requesting the URL from the remote server. This is intended to emulate browser behaviour.

JMeter embedded resources being downloaded when disabled

I have recorded a simple get/post test using the Blazemeter chrome plugin and am tweaking it in JMeter to be ready to use. However, the test fails because one of the embedded resources fails to load, which if it was correct, would be understandable.
I don't know if I am not understanding what I am seeing in the View Results Tree listener but I have some questions:
I don't need to download embedded resources but even though the box is NOT ticked on the http requests, they are still shown as downloaded. However, for the GET, these are dowloaded successfully.
I think that the post is failing and the same page is being returned by the server but when it comes to reloading the embedded resources, they all succeed except for one to fonts.googleapis.com, even though the same request always works for the get request
The failure is always the same each time I run it. Always, the embedded resources download correctly with GET and always that single 12th request to google fails with a 400.
Please can someone advise how to 1) Actually stop embedded resources from being downloaded and 2) work out how to debug why a second request to the same resource always fails even though it is simply an embedded font?
JMeter Chrome Extension adds HTTP Request Defaults configuration element which populates the values for all the HTTP Request samplers in its scope. So if you don't want to download embedded resources (although it's not recommended) you need to open "Advanced" tab of the Defaults configuration element and untick the box there
There is a special property which controls whether a problem with fetching an embedded resource is treated as failure or not, if you would like to download embedded resources but at the same time to ignore failures you can add the next line to user.properties file:
httpsampler.ignore_failed_embedded_resources=true
upon JMeter restart problems with embedded resources won't fail the parent HTTP Request sampler. See Configuring JMeter user manual chapter for more details if needed.

Prevent truncated HTTP response from being cached

We saw this issue on one of our dev machines - the vendor.js bundle in our Angular project had somehow gotten cached, while truncated, which breaks the web app until you clear the cache.
We do use browser caching (together with URL-hashing so caching doesn't prevent app updates).
Is there any way to prevent the browser from caching a truncated request? Actually, I would have thought that the browser has this built-in (i.e. it won't cache a request where the bytes header does not match the amount downloaded).
The browser where we reproduced the problem was Chrome.
I think I found the issue - for whatever reason, our HTTP Response was missing the "Content-Length" header in the Response Headers.
The response passes through 2 proxies so one of them might remove the "Content-Length" header.
What we did in such a case is to add a parameter for the request of a lib.
You just need to raise the number and next time the browser and the caches in between will fetch a new version from the server:
e.g. www.myserver.com/libs/vendor.js?t=12254565
www.myserver.com/libs/vendor.js?t=12254566

F5 BIG IP - ajax POST with HTTP response truncated

Jmeter 2.12.
I used a scenario fully functional in front of a reverse proxy Apache. Recently we 've replaced the reverse proxy with the F5 BIGIP technology and now my scenario hangs.
The problem is for a particular ajax POST request the HTTP response is truncated : i receive a 200 OK but the HTML content is not full (no html tags for example). When i post the same request with Firefox the full content is ok.
Note that i don't receive the http header Transfer-Encoding: chunked.
In this case what can be the difference between Firefox and JMETER ?
Anyone have an idea on how could i get the full html response ?
Thanks for any reply.
That completely depends on the settings on your F5 and what exactly you mean with "response is truncated" and "no html tags". Do you get the correct response but the html tags are stripped out? or is the response just truncated so you i.e. only get the first n bytes?
The best way to find out what is actually going wrong is to use something like fiddler in between and try to find the real difference between the responses, especially regarding the response headers (Content-Length, Transfer-Encoding, etc).
When you found the actual difference please post here so we can help you further.
On a sidenote, by any chance do you have some custom coding on the f5 (iRules) which react to different user-agent settings?
Given you send identical requests you should be receiving identical responses.
Use JMeter's View Results Tree listener to inspect request details, or even better compare requests which are being sent by Firefox and JMeter using a lower level network sniffer tool like Wireshark, detect the differences and configure JMeter accordingly to send the same request(s) as Firefox does.
The other reason might be JMeter truncating large response, by default JMeter displays "only" first 10 megabytes in the View Results Tree listener, if this is the case - you can add the next line to user.properties file:
view.results.tree.max_size=0
and restart JMeter to pick the property up - it will suppress response truncation and you will be able to view the full response data.
Alternative way of setting the property is passing it via -J command line argument like:
jmeter -Jview.results.tree.max_size=0 ....
References:
Full list of command-line options
Apache JMeter Properties Customization Guide

Jmeter cannot handle cookies for https

Being a beginner in Jmeter, met with necessity to run a simple flow:
To log in web-app using webdriver sampler
To get & store cookies
To make GET/POST requests within the web-app (e.g. navigate to any inner page)
Test runs succeed for http://, but failed on HTTP-request step with 404 for https:// (two different sites)
What has been done to resolve:
1. Cookie Manager was added to Thread Group, placed prior Samplers
2. jmeter.properties changed to:
CookieManager.allow_variable_cookies=true
CookieManager.save.cookies=true
CookieManager.check.cookies=false
Thus, after changing save cookies to true, I expected to see all cookies saved in Debug Sampler > JmeterVariables, but I don't (either for http:// or for https://)
3. Regexp extractor (placed above HTTP sampler) used as:
Reference Name: COOKIE_EXT
Regular expression: SSESSee2ec8d6b6eedd096cb782a386b4e5c3=(.*)
Template: $1$
Match No.: 1
Use empty default value
Put in GET request as:
name: cookie_ext
value: ${COOKIE_EXT}
As a result:
Response in Debug Sampler: COOKIE_EXT=
Request data: GET ?cookie_ext=
[no cookies]
4. Tried to find any additional Jmeter settings for https (e.g. TSL/SSL protocols). Seems there are no any required except specifying 'https' in HTTP sampler template. Played with Implementaion & Cookie Policy in HTTP Cookie Manager, but without effect.
What could be the reason?
(Jmeter 3.0, Google Chrome 51.0, Drupal 7.43)
I haven't seen any problems with handling cookies and HTTPS protocol so maybe you have misconfigured something.
Remember a couple of things:
Any properties changes should be done in user.properties file
You need to restart JMeter to pick the properties up
Given you have CookieManager.save.cookies=true you are storing cookies into JMeter Variables already, there is no need to use regular expressions. Moreover, in case your regular expression is wrong (it seems very weird to me) you may overwrite "good" cookie from the HTTP Cookie Manager with "bad" value from the Regular Expression Extractor.
See Using the HTTP Cookie Manager in JMeter guide for more information on working with cookies in JMeter

Resources