Open ambrosmiroslav opened 3 years ago
I made some "research" on this problem. It doesn't matter the POST or GET is used - the redirection itself is a problem when automatic redirection following is turned on (which is the default option).
The HTTP requests in artillery are sent by the Got library (https://www.npmjs.com/package/got). The artillery attaches an event listener to the response object to be informed by Got that the request/response was finished, see file core\lib\engine_http.js:
res.on('end', () => {
context._successCount++;
if (!maybeCallback) {
callback(null, context);
} else {
maybeCallback(null, res, body);
}
});
What seems to be a problem that Got sends two 'end' events in case of response redirection. One for the initial request (with the response status code 303 in my case). And one for the redirected content (with the response status code 200) - because Got follows the redirection automatically.
So the callback() function is called twice for one scenario step - and since this moment there are two "execution threads" which process the rest of the scenario instead of a single "execution thread". So each "execution thread" which encounters the redirection is duplicated and continues on its own. Thus my sample scenario with four redirects ends up with 2^4 "execution threads" alive...
I can create hotfix for my scenario:
res.on('end', () => {
context._successCount++;
if (code == 303) {
// do nothing
} else if (!maybeCallback) {
callback(null, context);
} else {
maybeCallback(null, res, body);
}
});
where code
is from the closure: let code = res.statusCode;
where the response is available.
But to become a general fix it should:
I think I could prepare PR but I'm not sure about the correctness of my solution. ;-)
I have a simple scenario:
which accesses my local HTTP server written in node.js:
This setup tries to simulate user login. The first GET request to /login displays HTML form. Then form submission with POST creates request to /login, the server accepts username and redirects client to /user. And finally user clicks to show some data with /list.
So there should be 4 requests in total (3x GET + 1x POST; the redirect is GET because the "303 See Other" is used). But my HTTP server reports 5 requests - the /list is doubled...
And funny thing - if I repeat the "-post" section in my scenario then I get more and more superfluous /list requests. :-) If I repeat my "-post" section four times I end up with 16 requests to /list... :-)
It seems like a new virtual user is created each time POST + redirect is processed and this new virtual user tries to finish started scenario?