Spread the love

How to stop a Test Process If that Is Hanged or Went To Infinite loop

Spread the love

This is pretty common problem while going towards CDCI(Continuous Development and Continuous Integration) process that many testcases hang and freeze due to several issues . Improper scripting (waiting for an element for infinite time , infinite loop etc)are the real cause of those issues. It makes the machine busy and does not leave for next execution which are lined up for further execution. Ideally they should be handled by script itself. But when we try to implement CDCI over scripts which are there for years, we hardly get that covered via script.

Now if we look the way we trigger a UFT or selenium execution, we can see we start a AOM process that intern triggers the run. Well that is good but not full proof to avoid such exceptions.

Here is a small thought to improve the triggering mechanism..
Instead of directly triggering an AOM script or a batfile or an ant script what we can do, we start two thread instead. The first thread keeps checking if the execution is going beyond specified time,meanwhile the second thread (child one) starts the exeuction.
Once the second one,if over, it kills itself . And if, it can not end execution then it will be alive. The first thread gets activated and kills the second one and frees up the machine to accept other execution which are lined up..

public class kickStarter {
private static final long timeout=4*60*60*100;
//this is the timeout period , we can wait maximum of that hours to see if the
// execution is over
private static boolean flag=false;
public static void main(String[] args)
{
OtherThread oth=new OtherThread();
oth.start();
//starts the other thread which kicks off the execution
long timer=0;
do
try{
Thread.sleep(1);
timer++;
//below block checks if the executing thread which is executing run
// is over or not. If completed it should not be alive
if(!oth.isAlive())
{
flag=true;
break;
//we want to break it as the other thread executed successfully over the
//specified time
}
}
catch(Exception e)
{
}
while(timer=timeout)
{
oth.kill();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
flag=true;
}
if(flag)
{
//clear UFT or selenium
}
}

}

the child thread will look like:

public class OtherThread extends Thread implements Runnable {
private volatile boolean isRunning=true;
public void run()
{
while(isRunning)
{
try{
Thread.sleep(1);
//call your AOM or batchfile or ant file here
kill();
//kill should be called after control comes back from execution
}
catch(Exception e)
{

}
}
}
public void kill()
{
isRunning=false;
}


}

image credit:http://www.understanditnow.com/

READ  Class UnknownError in Java

READ  Learn Exception Handling in Java Quick and Fast Manner




Spread the love
Animesh Chatterjeehttps://techtravelhub.com/
I am the founder and owner of the blog - TechTravelHub.com, always love to share knowledge on test automation,tools,techniques and tips.I am a passionate coder of Java and VBScript.I also publish articles on Travel ideas and great honeymoon destinations.Apart from these, I am a gear-head,love to drive across India. I have shared lots of articles here on How to travel several parts of India.Customization of cars aka car modification is my another hobby.Get in touch with me on ani01104@gamil.com

Related Articles

Super Keyword in Java Simplified

Super Keyword Super Keyword in Java Simplified: Java defines a special keyword called...

Comments

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Recent Posts

Super Keyword in Java Simplified

Super Keyword Super Keyword in Java Simplified: Java defines a special...

Learn Object Repository in UFT in An Efficient and Fast Manner

Object Repository in UFT The post will cover the following...

Learn What Primary Tools For Test Automation

Primary Tools For Test Automation According to the Gartner report...

EDITOR PICKS


Spread the love