Friday, 16 December 2011

Ever tried adding 2K+ comments to an article?

A few days back I encountered a strange behavior while working on an issue which I feel worth sharing. 

The test case is to check comments section when number of comments for an article are ‘n-1’, ‘n’ and ‘n+1’ (where n = 2000,  3000, etc.). My goal is to identify the point where the comment section breaks in lower environment with ‘n’ comments. I queried QA database and didn’t find much data to check all scenarios. Now my challenge is to quickly create dummy data in QA environment to identify the point where comment section breaks. 

How to quickly add bulk comments to an article?

To do this there are several approaches … some of them are
a)   Add entries (comments) manually till required number of comments were added.
Cons: Clumsy and time taking process.

b)   Write DB scripts to populate numerous records on one go.
Pros: Quick and efficient.
Cons: This approach works in most of the cases but not always. Also, it doesn’t seem to work when lot of tables re involved in the update. Moreover, it doesn’t mimic real time “add comment” functionality.

c)   Browser level automation script.
Pros: Quick and efficient.
Cons: Although this approach is far better when compared with (a) and (b) but, not the best! If we realize the fact that request / response at browser level will take good amount of time!

If not manually ... if not at DB level ... if not via. automation@browser level then what is the best approach to add bulk comments?

Automation at HTTP level is the best optimized way to deal in such scenarios. I chose HTTP level automation because comments can be quickly added at http level. Since the tests are done directly at HTTP level, http level test script doesn’t care about downloading all the embedded objects, rendering issues, HTML/JS changes on the page.

Refer below links for more information.
Rock & Roll With Http Level Testing

In the first attempt http test script ran for almost 18 hours and posted 2000 comments to an article.

Statistics (First Run):
No. of comments added: 2000
Min response time: 28.31 Seconds
Avg. response time: 33.25 Seconds
Max response time: 121.27 Seconds
Total run time: 66505.20 seconds (i.e. ~18 hours)


Good thing: I was able to add comments at http level :)
Bad thing: Http tests took much more time than I anticipated :(

I was very disappointed after looking at the response time as response time (Minimum, Average & Maximum) was huge! Keeping HTTP level tests aside, if I start posting comments manually I can comfortably post more than 2000 comments in less than 18 hours!

Question: Why http level test was damn slow? Why huge response time? What went wrong?

After looking at the huge response times for each http request I strongly felt that something went wrong and started analyzing the script and results. After some research I made a small change in test script and executed the tests. Interestingly, I observed drastic decrease in response time and tests completed in 49 minutes (i.e. less than an hour).

Statistics (Second Run):
No. of comments added: 2000
Min response time: 1.49 Seconds
Avg response time: 1.49 Seconds
Max response time: 2.97 Seconds
Total run time: 2994.84 seconds (i.e. 49.914 minutes)


One small change made Second test run 22 times faster compared with previous (First) test.
 
Do you like to know what the change is? Check below comments …

In the first run I used '%2F', '%3F', ‘%26', %2D encoded values in POST request body.
Sample:
postbody="context=tpc%2F287528%2FBOOKPAGE%2F28263&sat={PARSEDRESULT2}&actionableId=28263&actionableType=BOOKPAGE&actionTypeId=2&actionContent=Test+comments&successView=%2Fajax%2Fajax_tpcComments%3FactionableType%3DBOOKPAGE%26actionableId%3D28263"

In the second run I replaced '%2F', '%3F', ‘%26', %2D  with  ‘/’, ‘?’, ‘&’, ‘=’ in POST request body.
Sample:
postbody="context=tpc/287528/BOOKPAGE/28263&sat={PARSEDRESULT2}&actionableId=28263&actionableType=BOOKPAGE&actionTypeId=2&actionContent=Test+comments&successView=/ajax/ajax_tpcComments?actionableType=BOOKPAGE&actionableId=28263"

Simple change resulted in the Second test run 22 times faster compared with First test!

Comparison …

Statistics (First Run)
Statistics (Second Run)
No. of comments added: 2000
Min response time: 28.31 Seconds
Avg. response time: 33.25 Seconds
Max response time: 121.27 Seconds
Total run time: 66505.20 seconds 
                               (i.e. ~18 hours)
No. of comments added: 2000
Min response time: 1.49 Seconds
Avg. response time: 1.49 Seconds
Max response time: 2.97 Seconds
Total run time: 2994.84 seconds 
                               (i.e. 49.914 minutes)

Lesson learned:Do not use encoded values in POST request as most of the application servers take long time to decode and process any request”

Other related articles

Share this article with your friends/colleagues if it is worth sharing J

No comments:

Post a Comment