Ask a Question

Running test in Parallel.

alibaba82
Super Contributor

Running test in Parallel.

Hello,
I like the feature of running test in parallel but I have one issue and hoping you can help me solve this.

Most of my test start off by createing a user account. In this function i populate the username by using some random number that i generate in my external groovy file.

If the tests are running in a series, everything works fine as the numbers are unique across all test cases.

however, if I run the test in parallel, a lot of tests fail because the username ends up being the same in multiple testcases. we cannot have duplicate usernames.

The function I use for generating username is something like this

Calendar c = Calendar.getInstance();
String timeStamp = c.get(Calendar.MONTH).toString() + c.get(Calendar.DAY_OF_MONTH ).toString() + c.get(Calendar.HOUR_OF_DAY).toString() + c.get(Calendar.MINUTE).toString() + c.get(Calendar.SECOND).toString() + c.get(Calendar.MILLISECOND).toString() ;
String UserName = "QA"+ timeStamp;

Can you suggest a better way so I dont have collissions.

THanks

Ali
3 REPLIES 3
omatzura
Super Contributor

Hi Ali,

maybe you can just add a random number at the end? ie

String UserName = "QA"+ timeStamp + "-" + Math.random()

?

regards!

/Ole
eviware.com
alibaba82
Super Contributor

how would that solve the problem.
So lets say I have testcase A,B,C. Since tests are running in parallel, all of them would get the same value for username.
omatzura
Super Contributor

Hi Ali,

I interpreted your setup as creating a username in a groovy-step at the start of your testcase? Is that how you are doing it?

When you start the tests in parallell, they might well get the exact same timestamp, which is why you are getting the same usernames in some of your tests. The Math.random() adds another randomization which will hopefully be unique for each call..

Hope this helps!

regards,

/Ole
eviware.com
cancel
Showing results for 
Search instead for 
Did you mean: