Introduction

In some cases, some of your action(s) may hang for a long period of time or forever.

If it hangs for a long period of time, the result will be that your test will wait for this queue completion way too long than expected.
Imagine you are running 100 threads for 1 hour, but one of them complete in 4 hours. This means you will load your Application under test for 1 hour and then will wait 3 more hours until the last thread is done.

If you get an action hanging forever then your test will never finish.



Set max iteration timeout period

All threading patterns support setting max time (in seconds) for iteration execution:

// set max iteration timeout period to 5 minutes
pattern.setIterationTimeout( 5 * 60 );

In our example, we will not allow an iteration to last longer than 5 minutes.

If a timeout is reached the currently running action is canceled and marked as failed in Test Explorer UI. An error is logged about the iteration timeout and the thread goes to the next iteration(if there is such left).

In order to stop the long-running iteration we actually interrupt its thread.

Thread interruption is an expensive operation, so if it happens very often you may experience significant CPU usage.



Max queue timeout

There is one more way to achieve something similar. Please see the next code and read carefully its comments:

import com.axway.ats.agent.webapp.client.ActionQueue;
import com.axway.ats.agent.core.threading.patterns.FixedDurationAllAtOncePattern;

// start a queue, but in a non-blocking manner
// this is done by using *false* as the second input argument here:
loader.setThreadingPattern( new FixedDurationAllAtOncePattern( 200, false, 60*60*1000, 0 ) );

// run the queue as usual
// ...
// ...

// now the queue is running
// we will either do something else here, or we will just wait for the queue completion in 1 hour
Thread.sleep( 62*60*1000 );

// cancel this queue if still running
ActionQueue.cancelQueue( "My running queue" );

As you can see we start a queue which is expected to run for 1 hour. If not done in 1 hour and 2 minutes we simply shut it down.

Drawback

Compared to using iteration timeout, canceling a queue has a major disadvantage: If one thread hangs forever, it will stay like this until you cancel the queue at the end. This means this thread will be blocked all the time, on the other hand when using iteration timeout the thread will make new attempts after each iteration timeout.


Back to parent page

Go to Table of Contents