Gatling session variable gets overwritten for multiple users. How to fix this? - scala

So i am an absolute newbie to gatling and the documentation on their site is pretty meh. My scenario is that i have different users which execute one scenario each and during these scenarios they make requests and save the answer in a session variable which they need as a parameter for a following request during the same scenario. My problem is that i have multiple users running at the same time and these overwrite the session variable so that a user which started earlier refers to the wrong value in the session variable. my idea was to set up a global counter which increments as soon as a new user is initialized and starts with his scenario and to append this counter to the session variable. is this possible and if so how do i do it? i bet there is a way better way to fix this behaviour but as i said i have zero experience with gatling and how its working.
my users look like this
user("singleUpload")
.behavior {
feed(applicationCredentials)
.exec(USingleUpload.singleUpload)
the scenarios like this
val singleUpload = exec(RUpload.post)
.exec(RShare.get)
.exec(RDownload.get)
.doIfEquals("${attachmentSingleUpload}", "attachment.jpg") {
exec(RThumbnailDownload.get)
}
.doIfEquals("${attachmentSingleUpload}", "attachment.png") {
exec(RThumbnailDownload.get)
}
.exec(RDelete.delete)
and the request like this:
val attachment = ("attachment", "${attachmentSingleUpload}")
val post = http("RUpload")
.post("/attachment/upload/")
.queryParam("share", "true")
.formUpload("attachment", s"attachments/${attachment._2}")
.header("x-api-key", "${apiKey}")
.header("x-app-id", "${appId}")
.check(status.is(200))
.check(jsonPath("$..pkey").exists.saveAs("pkey"))
val get = http("RShare")
.get("/attachment/share")
.queryParam("pkey", "${pkey}")
.header("x-api-key", "${apiKey}")
.header("x-app-id", "${appId}")
.check(status.is(200))
.check(jsonPath("$..skey").exists.saveAs("skey"))
for example: i make an upload and save the pkey which i then use in the request to get an skey. if user #2 is fast enough with his upload to overwritter the pkey variable in the session then user #1 uses a wrong pkey in his request.

user("singleUpload")
.behavior {
There's neither user nor behavior methods in Gatling's API. If you really have this in your code, these are private customizations. Can't say what they do or if they're correct.
My problem is that i have multiple users running at the same time and these overwrite the session variable so that a user which started earlier refers to the wrong value in the session variable.
if user #2 is fast enough with his upload to overwritter the pkey variable in the session then user #1 uses a wrong pkey in his request.
This is absolutely impossible. Each virtual user has its own Session, isolated from the others'. You cannot store something in a given virtual user's Session and have another virtual user overwrite it. And there's absolutely zero chance of a bug in there.
I recommend that you reconsider how you came to this erroneous conclusion and investigate other possible explanations. This small piece you provided looks correct. Maybe you've simply uncovered a bug in your application and Gatling is just the messenger.
"the documentation on their site is pretty meh"
That's neither nice nor constructive. Maybe explaining what you think is lacking in the documentation? Have you gone through all of it? Have you checked the online courses?

Gatling sessions are isolated so overwritting is not really possible.
I am using saveAs in many simulations without any problems. The issue is somewhere else.

Related

Automatically send email about editing google spreadsheet

I'm working on a rather simple script which should handle new values in the spreadsheet and then send emails to specified addresses. And I faced with the problem. My code is listed below:
function onEdit(e) {
//part of the code for checking e.range to process only updated values
sendEmail();
}
function sendEmail() {
// arguments are missed only for demo
GmailApp.sendEmail();
}
While I'm using "simple trigger", my function "sendEmail()" works only if I start it from script editor. I allowed sending emails on behalf of my at first time and then function works fine. But if I'm changing the value in the spreadsheet - function "onEdit(e)" processes new data but function "sendEmail()" does nothing.
I partly solved this problem by using project's triggers from "current project's triggers" menu. In that case, function "sendEmail()" works properly, but I have no access to the information about update.
For my purposes I could use just second way and find new values "manually" every time, but I wish to optimize this work.
So, my questions are:
Is the process I described above proper or I made a mistake
anywhere?
If process proper, is where a way to combine both cases?
Thanks!
You correctly understood that (as the docs say) simple triggers cannot send an email, because they run without authorization. An installable trigger, created via Resources menu, can: it has the same rights as the user who created the trigger. If it is set to fire on edit, it will get the same type of event object as a simple trigger does.
So, a minimal example would be like this, set to run "on edit":
function sendMail(e) {
MailApp.sendEmail('user#gmail.com', 'sheet edited', JSON.stringify(e));
}
It emails the whole event object in JSON format.
Aside: if your script only needs to send email but not read it, use MailApp instead of GmailApp to keep the scope of permissions more narrow.

ScalaCheck generator for web URLs

Wondering if anyone had to do this in using ScalaCheck: Create a custom generator for spitting out large number of URLs. Actually there is a caveat to this that I want to test a service which accepts ONLY valid/working web URLs. I am thinking if I get a large number of valid external/WEB URLs in a file and somehow feed in to the custom generator, only can make this possible?
something like
val genUrls = for {
url <- "URL1" | "URL2" | "URL3"
}yield url
does this sound like a reasonable and actually more importantly doable approach?
UrlGen seems to give that, since uses a list of top urls, but cannot find the artifact in maven repo anywhere. Raised an issue.
PS
You can always add .suchThat(exists), where exists does make sure the URL exists during the test or better yet do it once, before the start of the tests, i.e. making sure all these guys exist.

Sugar CRM SOAP API - Problems with Auto Incrementing Key and set_entry

I've tried the SugarCRM forums for this problem as well, but I was wondering if anyone here has run into a similar issue and would be willing to share the solution.
We are working with the SOAP API for Sugar CRM via the Sugar On Demand system and their appears to be a problem - which at the moment looks very much like a bug.
The Module we trying to work with is the case module. We are running the set_entry action on the case module. It worked the first time we did this, but now it refuses to allow us to enter any more modules. I've checked the log files and made sure that we are submitting anything in the case_number field to over ride this, but whenever we try to add a new case we get the following error showing up in the log:
Query Failed: INSERT into cases set id='bb53030e-0f2f-5787-f403-4dde57cde36e', name='New RMA Request Test', date_entered='2011-05-26 13:37:15', date_modified='2011-05-26 13:37:15', modified_user_id='b1256ced-011d-7c1a-e1f3-4d4004ea4e9a', created_by='b1256ced-011d-7c1a-e1f3-4d4004ea4e9a', description='fjdlkas', deleted='0', assigned_user_id=null, team_id=null, team_set_id='ded0fbb0-c5dc-74ee-0622-4d22eb653a80', type=null, status=null, priority=null, resolution=null, system_id=1, work_log=null, account_id=null: MySQL error 1062: Duplicate entry '2147483647' for key 2
This is a bit odd for a few reasons:
I've confirmed that the corresponding key is auto-incrementing.
I am not submitting that number anywhere.
The next auto-increment value when I check the setting in the Studio is actually 2147483648.
Can someone explain what I need to do with the SOAP API to stop it from overriding the auto-increment value on my table?
Edit: I get the same error if I try to add a case via the interface, so I suspect this could be a problem with the CRM configuration itself rather than a SOAP related issue like I originally thought.
I would try to increase the size of the case_number field from an int(11) to something bigger and see if that fixes the issue.

Customize Error Reporting via E-mail in Pylons

I am sending myself WebApp error reports from Pylons when users hit critical errors and I would love to be able to get the full output of session[] in the reports and customize it to my liking, but I've got no idea how to do that, or where the report is actually created / put together.
Anyone know how I can accomplish that?
The short answer is that you will have to roll your own for this functionality. WebError is the package used to handle this, and it doesn't provide any extension points. Your best bet may be to use a fork of it with your changes, although even then the code is not pretty.
I thank Michael for answering me, without really giving me anything to build on. That meant I had to figure it out myself, and that's always a good thing :)
What I did was, I looked at /config/middleware.py in my Pylons project and found this line:
app = ErrorHandler(app, global_conf, **config['pylons.errorware'])
I made my own ErrorHandler def and my own ErrorMiddleware class at the top of the middleware.py file:
class ClaraErrorMiddleware(ErrorMiddleware):
def exception_handler(self, exc_info, environ):
# do what ever you want with the exc_info or environ vars
super(ClaraErrorMiddleware, self).exception_handler(exc_info, environ) # call parent
pass
def ClaraErrorHandler(app, global_conf, **errorware):
if asbool(global_conf.get('debug')):
return ErrorHandler(app, global_conf, **errorware)
else:
return ClaraErrorMiddleware(app, global_conf, **errorware)
So now, I can throw in some extra variables I want to be sent with my error emails. Simple enough ...

How do I get the text-form verification code when doing auto site access in Perl?

I'm playing around with Win32::IE:Mechanize to try to access some authentication-required sites automatically. So far I've achieved moderate success, for example, I can automatically log in to my yahoo mailbox. But I find many sites are using some kind of image verification mechanism, which is possibly called CAPTCHA. I can do nothing to them. But one of the sites I'm trying to auto access is using a plain-text verification code. It is comnposed of four digits, selectable and copyable. But they're not in the source file which can be fetched using
$mech->content;
I searched for the keyword that appears on the webpage but not in the source file through all the files in the Temporary Internet Files but still can't find it.
Any idea what's going on? I was suspecting that the verification code was somehow hidden in some cookie file but I can't seem to find it :(
The following is the code that completes all the fields requirements except for the verification code:
use warnings;
use Win32::IE::Mechanize;
my $url = "http://www.zjsmap.com/smap/smap_login.jsp";
my $eccode = "myeccode";
my $username = "myaccountname";
my $password = "mypassword";
my $verify = "I can't figure out how to let the script get the code yet"
my $mech = Win32::IE::Mechanize->new(visible=>1);
$mech->get($url);
sleep(1); #avoids undefined value error
$mech->form_name("BaseForm");
$mech->field(ECCODE => $eccode);
$mech->field(MEMBERACCOUNT => $username);
$mech->field(PASSWORD => $password);
$mech->field(verify => $verify);
$mech->click();
Like always any suggestions/comments would be greatly appreciated :)
UPDATE
I've figured out a not-so-smart way to solve this problem. Please comment on my own asnwer posted below. Thanks like always :)
This is the reason why they are there. To stop program like yours to do automated stuff ;-)
A CAPTCHA or Captcha is a type of
challenge-response test used in
computing to ensure that the response
is not generated by a computer.
This appears to be an irrelevant number. The page uses it in 3 places: generating it; displaying it on the form next to the input field for it; and checking for the input value being equal to the random number chosen. That is, it is a client-only check. Still, if you disable javascript it looks like, I'm guessing, important cookies don't get set. If you can execute JavaScript in the context of the page (you should be able to with a get method call and a javascript URI), you could change the value of random_number to f.e. 42 and fill that in on the form.
The code is inserted by JavaScript – disable JS, reload the page and see it disappear. You have to hunt through the JS code to get an idea where it comes from and how to replicate it.
Thanks to james2vegas, zoul and Shoban.
I've finally figured out on my own a not-so-smart but at-least-workable way to solve the problem I described here. I'd like to share it here. I think the approach suggested by #james2vegas is probably much better...but anyway I'm learning along the way.
My approach is this:
Although the verification code is not in the source file but since it is still selectable and copyable, I can let my script copy everything in the login page and then extract the verification code.
To do this, I use the sendkeys functions in the Win32::Guitest module to do "Select All" and "Copy" to the login page.
Then I use Win32:Clipboard to get the clipboard content and then Regexp to extract the code. Something like this:
$verify = Win32::Clipboard::GetText();
$verify =~ s/.* (\d{4}).*/$1/msg;
A few thoughts:
The random number is generated by something like this in Perl
my $random_number = int(rand(8999)) + 1000; #var random_number = rand(1000,10000);
And then it checks if $verify == $random_number. I don't know how to catch the value of one-session-only $random_number. I think it is stored somewhere in the memory. If I can capture the value directly then I wouldn't have gone to so much trouble of using this and that extra module.