Saturday, May 21, 2011

Using Grinder: some notes

Grinder is a free multi-purpose open source load testing tool. It can be used to drive Java/Jython tests as well as Web Browser tests, functional as well as load. Install Jython as well as Grinder.



There is also en Eclipse plugin to help run/debug Grinder scripts - called GrinderStone, you can find info about it here



To record and playback a Browser Test:



1) Configure your Browser to use a Proxy (e.g. localhost 8001 is the default - set this for http and https)

2) Set your classpath to include grinder/lib/grinder.jar and jython's jython.jar (not grinder's jython.jar !!!)

3) Start Grinder in Proxy Mode: java net.grinder.TCPProxy -console -http > grinder.py

launch with -localPort XXXX to change the Proxy port

4) Start your Browser and Do Your Actions

5) Press "Stop" on the TCPProxy console and the generated script will be written to grinder.py.



grinder.py is in python and can be edited to your heart's content (replace hard-coded users with variables read in from a file, for example)



To replay the file, create a grinder.properties text file with at least this setting:

grinder.script grinder.py

and run it

java net.grinder.Grinder grinder.properties



log files will be output in the current working directory, text and data (csv suitable for loading, parsing and charting in a spreadsheet)



other info here for proxy usage: http://grinder.sourceforge.net/g3/tcpproxy.html



for multi-threaaded, define more threads per process in your grinder.properties file:

grinder.processes 1

grinder.threads 100



if you customize your script to use python modules, you will need to set the python.home and python.path environment variables and pass them into your command-line arguments

java -Dpython.home=/Users/YOU/jython2.5.2 -Dpython.path=/Users/YOU/jython2.5.2/lib net.grinder.Grinder grinder.properties

and in grinder.properties:

grinder.jvm.arguments = -Dpython.home=/Users/YOU/jython2.5.2 -Dpython.path=/Users/YOU/jython2.5.2/lib





*Some lessons learned the hard way*:



disable cookies (that is to say, don't let ourselves get in the way of the record/replay process as far as cookies are concerned. leave your cookies alone)

connectionDefaults.setUseCookies(0)



avoid complex Wicket GETS

everything gets recorded but not everything needs to be replayed. for example, something like this:

self.token_wicketinterface = \

':2:ARightColumn:AudioAppsPanel:rows:1:cols:2:

cannot be relied on.

if you have a page method like that, simply "return ''" at the beginning of the method to avoid wicket/irresolution hell



definitely use the TCPProxy (formerly TCPSniffer) to watch what the hell is going on

java net.grinder.TCPProxy

and if you do so while replaying, make sure your replay test is using the proxy by uncommenting this line

connectionDefaults.setProxyServer("localhost", 8001)



*really gnarly grinder stuff*

say you have recorded a script and you want to add stuff to it from another recorded script.

yikes!!



several steps are involved because numbers will collide and it's all numbers in grinder (requestXXXX, pageXXX, TestXXXX)

1. in the new script, find all the 'request' methods of the areas you want to add, and give them real names



e.g. change

request1700 = HTTPRequest(url=url1, headers=headers4)

request1700 = Test(1700, 'GET redButton_White_150.png').wrap(1700)

request1701 = HTTPRequest(url=url1, headers=headers4)

request1701 = Test(1701, 'GET collapseButton.png').wrap(request1701)



to:

requestAolExtra1700 = HTTPRequest(url=url1, headers=headers4)

requestAolExtra1700 = Test(1700, 'GET redButton_White_150.png').wrap(requestAolExtra1700)

requestAolExtra1701 = HTTPRequest(url=url1, headers=headers4)

requestAolExtra1701 = Test(1701, 'GET collapseButton.png').wrap(requestAolExtra1701)



change the pageXXXX method to match (request170x will be page17, for example)

change:

def page17(self):

to:

def pageAolExtra17(self):



how change the instrumented 'Test' as well

change:

instrumentMethod(Test(1700, 'Page 17'), 'page17')

to:

instrumentMethod(Test(1700, 'Do Aol Extra'), 'pageAolExtra17')



now, copy those changed lines and methods (request lines, former 'page' methods, and InstrumentMethod lines) into the original file: BUT WAIT!! The Test number may well collide with some existing one, so change it too, for example by adding '1' or '2' (etc) in front of the number, e.g:

instrumentMethod(Test(11700, 'Go To Extras Tab'), 'pageAolExtra17')



In the __call__ method, pageXXX methods are called. Here is where you can call your newly renamed page methods as well. The pageXXXX methods call the requestXXXX methods, which use the Instrumented Test methods to make the actual call.



Also watch out for headers referenced in the new request methods - make sure you merge the right ones properly into the original file.

No comments:

Post a Comment