[ptt-users] Stress Test data from input file

Kyle Bell kylebell at tango-networks.com
Fri Dec 22 11:08:16 PST 2006


To further this discussion, other references I recommend are the "Python
Cookbook", "Jython for Java Programmers", and "Jython Essentials".  I've
found all three of these books useful as references.

Also the following link is the best reference I've found for simply
finding functions to use and discovering their applications:

	http://www.python.org/doc/lib/lib.html

Merry Christmas!

-Kyle

On Fri, 2006-12-22 at 12:03 -0500, Mark.Lutton at thomson.com wrote:
> For anyone who doesn't know Python, it's worthwhile getting a book and
> going through it.  (I'm reading "The Quick Python Book" by Harms and
> McDonald, published by Manning.)
>  
> It's fast and easy to learn if you know Java or C++ or other object-
> oriented languages.
>  
> Unlike Java or C++, you can add members to objects at any time.  For
> example:
>  
> In the line
>  
>    testcase = newtestcase()
>  
> you create an object named "testcase" of class test.  Then in the line
>  
>     testcase.userdata = userdatefile.readline()
>  
> you add an "instance variable" to testcase.  It's like defining a
> member of a class, but you do it on the fly and it's only in this
> instance.
>  
> In the module test.py, which defines the class test, you can reference
> that variable:
>  
>   print self.userdata
>  
> (If it doesn't exist, you'll get an exception, which you can handle
> with "try - except" if you want.) 
>  
> You can play with Jython by writing a script in TestMaker or by
> running it interactively.  Here is a Windows batch file to run Jython
> alone:
>  
>   @echo off
>   set java_home=C:\j2sdk1.4.2_08
>   SETLOCAL
> 
>   if "%TESTMAKER_HOME%"=="" set TESTMAKER_HOME=C:\TestMaker44
>   if "%JYTHON_HOME%"=="" set JYTHON_HOME=%TESTMAKER_HOME%\lib\jython
>   set TMCP=%TESTMAKER_HOME%\lib\jython\jython.jar
>   set LOCALCP=%TMCP%
>   echo CLASSPATH=%LOCALCP%
> 
>   "%JAVA_HOME%\bin\java.exe" "-Dpython.home=%JYTHON_HOME%" -classpath
> "%LOCALCP%" org.python.util.jython %ARGS%
>   ENDLOCAL
> 
> 
> 
> ______________________________________________________________________
> From: users-bounces at lists.pushtotest.com [mailto:users-
> bounces at lists.pushtotest.com] On Behalf Of Thieme.Geoff
> Sent: Thursday, December 21, 2006 6:40 PM
> To: TestMaker users list
> Subject: RE: [ptt-users] Stress Test data from input file
> 
> 
> Based off a couple of responses I figured out how to get this working
> the way I wanted. Using the code below I'm able to read a new record
> for each loop used by an agent.
>  
> In master.py I added:
> def startTestCase( usercount, duration ):
>     ''' 
>     Instantiate a thread for each virtual user (concurrent request).
>     '''
>  
>     global record, logpath, callback_running, callback_record, running
>  
>     print "Start test with", usercount, " virtual users for",
> duration, "minutes."
>  
>     agentid = 0
>     tr = []
>     running = 1
>      userdatafile = open('S:\\d3a\\docs\\TestMakerStressTesting\
> \xstest\\userdata.tsv', 'r')
>      userdatafile.readline()  # Remove header line from input file
>  
>     for i in range( usercount ):
>         print ".",
>  
>         agentid += 1
>         
>           testcase = newtestcase()
>           testcase.userdata = userdatafile.readline()
>         tr = TestRunner( i, duration, usercount, testcase,
> callback_running, callback_record )
>         tr.start()
>     
>         waitSeconds( startupdelay )
>  
>      userdatafile.close()
>     print " >start",
> 
>  
> And in test.py I added:
>         userid, passwd, billid = self.userdata.rstrip().split( '\t' ,
> 2 )
> 
>  
> Thanks for the help guys,
> Geoff
> 
> 
> 
> ______________________________________________________________________
> From: users-bounces at lists.pushtotest.com [mailto:users-
> bounces at lists.pushtotest.com] On Behalf Of Mark.Lutton at thomson.com
> Sent: Wednesday, December 20, 2006 8:27 PM
> To: users at lists.pushtotest.com
> Subject: RE: [ptt-users] Stress Test data from input file
> 
> 
> Is the code to open the file in a different module?  Try making
> userdata an instance variable:
>  
> In master.py:
>    test.userdata=open('S:\\d3a\\docs\\TestMakerStressTesting\\xstest\
> \userdata.tsv', 'r') 
> 
> in test.py:
>   userid, passwd, billid = self.userdata.readline().rstrip().split
> ( '\t' , 2 ) 
> 
>  
> Mark Lutton
> Business Intelligence Services, a Thomson Business
>  
> 
> 
> ______________________________________________________________________
> From: users-bounces at lists.pushtotest.com on behalf of Thieme.Geoff
> Sent: Wed 12/20/2006 6:03 PM
> To: TestMaker users list
> Subject: [ptt-users] Stress Test data from input file
> 
> 
> 
> I'm using TestMaker 4.4. I created an xstest\test.py file that reads
> input data from a file. My code works for running just test.py and
> getting variable user data from userdata.tsv. Now I'm trying to use
> xstest\master.py to create a stress test which will use a different
> row of data from my input file for each test.
> 
> I tried a couple approaches but neithor worked. When I open the input
> file as userdata in master.py, test.py is unable to access the
> userdata variable to do a readline().
> 
> Any suggests on getting this to work? I found no example scripts which
> get test data from input files. 
> 
> 
> Working code from test.py: 
> ... 
>     def setUp( self ): 
>         ''' Add any needed set-up code here. ''' 
> 
>         # Remove header line from input file 
>         self.log( 1, "Using the userdata values :%s:" %
> ( userdata.readline() ) ) 
>         
>         self.log( 1, "test: setUp" ) 
>         self.config() 
>         
>     def runTest( self ): 
>         ''' Run the test ''' 
>         self.log( 1, "test: runTest" ) 
>         
>         # Read data from input files 
>         self.log( 1, "Testing with:") 
>         
>         # Get 3 tab seperated data values, ignore any extra values
> listed on that line 
>         userid, passwd, billid = userdata.readline().rstrip().split
> ( '\t' , 2 ) 
>         self.log( 1, "userid :%s:" % ( userid ) ) 
>         self.log( 1, "passwd :%s:" % ( passwd ) ) 
>         self.log( 1, "bill id :%s:" % ( billid ) ) 
> ... 
>     The settings below were found in the Advanced Options panel of the
> Recorder. 
>     ''' 
> 
>     test = test( 1, 'console file ', 1, '20.|300|301|302|303|304|307|
> 401|403|408|41.', 'log.xml', 0, 1, 1, 1, 1, 'test', 1 )
> 
>     # Run test using userdata input file 
>     try: 
>       userdata=open('S:\\d3a\\docs\\TestMakerStressTesting\\xstest\
> \userdata.tsv', 'r') 
>       
>       test.setUp() 
>       test.runTest() 
>       test.tearDown() 
>     finally: 
>       userdata.close() 
> 
> 
>     test.closelog() 
>     print "done" 
> 
> 
> Thanks for any help,
> Geoff 
> 
> 
> _______________________________________________
> Users mailing list
> Users at lists.pushtotest.com
> http://lists.pushtotest.com/mailman/listinfo/users



More information about the Users mailing list