Posterous theme by Cory Watilo

Rapid Load Test data generation using python

I have a requirement that I need to create a set of SQL queries to insert a load of test data into a test database for a load test.  The problem I have is that some of the data I need to dynamically change and some of the data has incremental patterns that I need to create in certain columns.

One approach that I have used is to create an SQL template command and swap in values inbetween placeholders.  I have a rules engine - which is essentially a switch statement that I can use to fill in depending on the position of the placeholder.  Its not too complex, and its not too clever.  I need something simple to debug when generating large volumes of data. 

At the moment all the values are hardcoded, but its a python script - its not going to take a lot to modify the script itself to create the data.  I could have used external configuration files, or pass in a load of parametres but then I need to create more code to deal with this.

So the code looks like

 

class SQLGenerator():
  def __init__(self):
    self.SQLCommand = "INSERT INTO TABLE_FOOBAR VALUES ({0},{1});"
 
  def run(self):
    for columnPos in range (0,self.countSwappedValues()):
      value = self.ruleEngine(columnPos,12)
      self.swapValues(value,columnPos)
    print (self.SQLCommand)
 
  def ruleEngine(self,columnPos,number):
    return {
      0: self.generateLeadingZeros(5,number),
      1: "Account"+self.generateLeadingZeros(5,number),
    }[columnPos]

  def countSwappedValues(self):
    leftBracket = self.SQLCommand.count('{')
    rightBracket = self.SQLCommand.count('}')
    if (leftBracket == rightBracket):
      return leftBracket
    else:
      return 0

  def swapValues(self, value,index):
    replaceStr = "{"+str(index)+"}"
    self.SQLCommand= self.SQLCommand.replace(replaceStr,value)

  def generateLeadingZeros(self, noLeadingZeros, number):
    result = ""
    for x in range (0,noLeadingZeros - len(str(number))):
    result = result + "0"

    result = result + str(number)
    return result

s = SQLGenerator()
s.run()

What I need to do - is wrap around a loop for the number of items I need to generate, substitute more complex SQL and change the rules engine for that SQL and output each generated SQL line to a file.  Where I print out the SQL is where I would write to file.   

Its not an amazing all conquering solution, and there is scope for extending this to run from external configuration but since its fairly lightweight - it should be quick to use and debug.  Python is a good tool for rapidly solving some issues such as data generation.

Delaying Http requests using JMeter and Test Action

I'd thought I'd post this, as a reminder to myself not to use the constant timer for delaying two http requests in JMeter.  I had a mis-understanding of what constant timer should be used for :-) Basically, I have a load test scenario where I need to delay a time between two http requests.  Initially I thought this would be achieved by using a constant timer - but for what I wanted to achieve, the behaviour of constant timer appears to apply a constant delay across all http requests, not just a delay between sequential requests.  

What I actually needed to use was a Test Action which is classified under Add->Sampler->Test Action menu selection when you create the test plan.  It is configured by adding the Sampler inbetween the http requests you wish to delay and setting the current thread to pause for a certain amount of milliseconds.

With the attached 2nd screenshot of the test plan, I have shown an incorrect setup of the constant timer.   (I wanted a delay after the makecall web request) - and a setup of the Test Action, I have placed this not as a child of the http request, but after the http request I want a delay after. The first screenshot shows this setup as a delay as part of a loop between makecall http requests.

Capture2
Capture

 

If all else fails - believe in you

If I had to convey one message to someone about life, it would be the strong desire to cultivate an inner sense of confidence in your own abilities.  I believe success and survival in life depend on this. 

We live in increasingly difficult times.  Stresses are out there waiting for you.  Someone can "fail" at any point in life, whether it be through failing to pass an exam, dropping out of university, failing to get a job,  comments about abilities at work, having a job and getting made redundent, splitting up with a girlfriend - the list of things life can throw at you to trip you up and screw your confidence is long.   How about a bug that was so obvious how did it get into live environment, have you tried switching the server on ;-) 

To me, it is how you deal with failure that to me determines whether you are a successful person, not how much you earn or how many possessions you have. Having ultimate success in life, is to master a complete understanding of yourself, controlling inner fear of failure and cultivating a strong belief that you can do and achieve anything regardless of how many times you fail to the outside world.  If the whole world "is out to get you" and you still believe that your invincible, you are in your mind invincible.  Conversely, if the whole world thinks your amazing, and in your own mind your useless, you are useless.  Bad things happen when you think your useless, you end up ultimately getting ill.

So this means, its 100% upto you and how you think of yourself that will determine in life if you succeed.  How do get confidence?  Keep telling yourself each day that your amazing. :-)

Uncertainty principle in software testing

There have been a couple of interesting blog posts about comparing Schrodingers cat to software testing and the paradox of the cat in the box being both dead and alive.  Basically you can not determine the state of the cat until you observe the cat in the box and take a look.

See:  Elisabeth Hendrickson on http://testobsessed.com/blog/2012/01/05/what-software-has-in-common-with-schr... and http://testsheepnz.blogspot.com/2012/01/schrodingers-code.html?utm_source=fee...

But I think both these posts don't focus enough on the key point of the anology.  The paradox is that the cat is both dead and alive at the same time, until you observe and open the box.  The problem is by opening the box you have influenced the result.  The key point is that it is the act of observation that interferes with the results.  I don't think it makes sence to talk about probabilities, and collapsing waveforms. Why not talk simply talk about throwing a coin in the air and seeing if it lands head or tails?  You don't know the state of the coin until you throw it, cover it and look at it?

A better Quantum Physics analogy is to look at the uncertainty principle and you can apply that to testing.  (The more accurate you measure the position of a particle, the less you can measure the momentum, and vica-versa.)  This correlates nicely to performance testing.  Since, the more accurate you try to observe something, the more you influence the result.   By setting up regular performance counters, you are measuring the system under test, but the more frequent you measure, the more CPU and resources will be applied to capturing the performance characteristics and eventually you will just measure the resources required to measure performance characteristics.  You can certainly flood the network with performance data.  The less you measure, the more you lose granularity of what the system was doing in smaller time segments, but you are capturing more realistic behavour.  Conversly, the more you measure, you will capture behaviour in smaller time slices but will lose resolution of what the system is really doing.  Like all these things, measure in moderation :-)

Surely "Hello World" in Basic has no bugs...

Consider:

10 PRINT "Hello World"
20 END

Surely there are no bugs in this code, written in Basic.

I can tell you 100% - that there are indeed no bugs in the code. 

However, that does not mean there are no bugs associated with the code.

As a thought experiment if you had to send this program to the most distant man made object in space - Voyager 1 - which has a Basic Interpreter onboard and is billions of miles away from Earth. Is this the smallest footprint that we would have to send across space?  

We could shrink it further:
1 PRINT "Hello World"

Also was printing "Hello World" the original indended use? Did the user want "Hello World" to be output?  Surely in this case you could print "Hello There"  :-)  What about colour? Font size?  And language?  Not all aliens would be able to read English. ;-)

What about impatient aliens?  Is this the fastest way of printing "Hello World" to the screen? No its faster if written in Assembler.

From a technical point there still could be bugs in the way the code is run.  Since Basic is an interpreted language, you need an intermediate piece of software that can run the code.  The code is syntactically correct, it should run in a Basic Interpreter, but will that Interpreter function correctly?  What if you run it a million times?  Does the interpreter have a memory issue?  Underlying components could cause faults in the execution of the program. 

Even with the simplest of programs, there are many factors that need to be considered in testing.  I would argue that intended use is critical here and would determine the degree of testing depth.  A small program that could be sent to be executed to Voyager, the most distant still functioning man made object, with a state of the art Basic interpreter as a command processing unit, should have significantly more depth and careful testing involved than an equivilent program created for a website.  The risk involved determines this.  Basically Voyager 1 could stop working.  Especially if you had a GOTO 10 in there.  Your not going to fetch that puppy easily if you have a loop of death.    Game over. 

The risk with a website? Some end users may get the hump, well you can recover from it.  Don't do it again, and code in a better language. GOTO 10 is so 80's.  

If users do not encounter any bugs - do they exist?

The above is an Interesting question, tweeted by Rosie Sherry founder of Software testing club , see:  https://plus.google.com/u/0/117838906942611692415/posts/KUuujdK7RHD

If a tree falls in the forest and no one is around to hear it does it make a sound?

To answer these types of question, it really does depend on your philosophy and definitions of the words.  You can answer that since no-one is around to hear the sound - then the sound does not exist.  To me I think this is a Solipsismic philosophical view.  The fact it only exists if someone perceives it - is one arguement.  Quoting from wikipedia "Sound is a mechanical wave that is an oscillation of pressure transmitted through a solid, liquid, or gas, composed of frequencies within the range of hearing and of a level sufficiently strong to be heard.".  So from this definition, it has to be heard or detected to be a sound.

Extracting from this arguement and relating this to bugs.  Any bugs that remain undetected by anyone, don't exist.  So if users don't experience any bugs do any bugs exist?  No.  Not yet.  And users and not yet are keywords.   Time and use are the factors in evaluating good software.  Looking at time and use of software, looking at bug counts gives an indication of how good a piece of software is in delivering quality.  Software which works for a week with no bugs detected is great.  However how are users exercising the software?  Software which works for years with many users having no bugs detected is the goal.  However given enough time and a weird odd use case - a bug in this software may materialise into the world :-)

Python splicing - a powerful way to manipulate strings

I've been using Python at work to help with automation tasks.  I'm very impressed with the simplicity of the language and how powerful it is.

One of the most common things in programming / scripting is extracting and manipulating data.    You may want to read a file, look for a data item in that file, store that item as a string and then concatinate that with another piece of data.

Python has a powerful technique of manipulating strings.  Its called splicing.  Basically works on the principles of an array.  If you have a string variable - a = 'This contains some string'.  You can access individual characters in this variable in a similar manner to other languages such as a[0] = 'T' a[1] = 'h'.  Etc...

Now there is a great, really great answer to a question on stackoverflow,  (see: http://stackoverflow.com/questions/509211/good-primer-for-python-slice-notation)  which I'm going to echo - since I want to keep a record of things like that in my notebook, and don't want to store that answer as a bookmark or in delicious.

Basically, and I quote directly from the site:

<Quote>

a[start:end] # items start through end-1
a[start:]    # items start through the rest of the array
a[:end]      # items from the beginning through end-1
a[:]         # a copy of the whole array

There is also the step value, which can be used with any of the above:

a[start:end:step] # start through not past end, by step

The key point to remember is that the :end value represents the first value that is not in the selected slice. So, the difference beween end and start is the number of elements selected (if step is 1, the default).

The other feature is that start or end may be a negative number, which means it counts from the end of the array instead of the beginning. So:

a[-1]    # last item in the array
a[-2:]   # last two items in the array
a[:-2]   # everything except the last two items

A point to note is "if you ask for a[:-2] and a only contains one element, you get an empty list instead of an error."

</Quote>

Now I personally think thats the best explanation I've seen on this subject.  If that guy who answered has written a book on programming I would buy it straightaway.  Such an awesome, straight to the point explanation.  I just need to memorise that - it should'nt be too hard, and would be very powerful to use when scripting :-)

Goodbye 2011 - hello 2012

Another year passes.  Time to reflect.

Lessons learnt this year.

  • Take control of your own destiny in your career.
  • Communication with other people can be difficult.  Always remain calm and professional at all times in all forms of communication at all times, concentrate on facts and develop awareness of when other people are not being professional and don't rise to it. 
  • 2011 - social media communication is mainstream.  You now need to be professonal in online activities at all times.
  • A fast moving industry requires a constant pursuit of updating skills.  To remain competitive as a software professional you need to master your own training.

What I would like to achieve next year.

  • I would like to re-kindle my passion for learning.  I feel I reached a point in my life towards the end of 2012 where I lost a bit my drive for learning.  I would try and follow Bob Martins advice in setting sometime aside for teaching myself some new skills.  I don't think I can master 20 hours extra a week, but the point of setting some time is still valid and achievable.  Start small and work up to increasing the amount of time.
  • I would like to develop inner peace in both my personal life and professional life.  A calm mind produces the best results.  As technology converges, and the pace of communication  quickens, change is constant.  To give myself the best change of deveoping inner peace I would like to pursue meditation and develop mindfulness by looking into going to local Buddhism meditation classes and looking to eastern Philosophy.  I also will look to continue going to the gym and exercise as that is a very good way to developing peace as well.

That would be it for 2012 - develop inner peace and rekindle passion for learning skills :-)  Wishing everyone a good and happy 2012.

The problem of saying bruce lee was a tester...

and drawing parallels between his life and that of a software tester is that there isn't one.  :-) I wanted to write something controversial because my initial impressions were that it was a cheesy way of writing about something, but actually no - my initial thoughts suck, and they really really suck :-) I actually think its an incredibly powerful way of expressing and developing ideas.  If someone can extract details of a philosophy in one discipline and highlight similarities in another discipline its a very creative way of writing, and also forms the basis of good research.  This approach encourages you to think about interconnecting ideas and I believe that all ideas and concepts are interlinked.  I think you can pick any two subjects in the universe and you should be able to interconnect the two.    

Yeah sure you make joke,  drink enough ale or smoke enough heavy stuff, you may well be able to link drying paint to how Bruce lee lived.  Well he was made of atoms - and paint consists of atoms so theres one immediate link before a brew.  But on a serious point, extropolating patterns from one discipline to another is very interesting idea, since you can look to see how techniques used to solve problems in one field are possibily transferable in other field.  Writing these types of articles are great way to gain insight into a topic and I think should be encouraged. 

The original link is here: http://davidstest.posterous.com/was-bruce-lee-a-tester