Reply
Contributor
AshwiniRao
Posts: 22
Registered: 09-02-2009
0

BREAK command does not work when the LOOP is invoked as a thread

Hi team

 

I have a testcase scenario as below. I am trying to use parallel threading concepts and am stuck. Can anyone please help.

 

Test case:

  1. Login to the device twice with 2 different session handles
  2. Execute command1 on session_handle1 (wrapped inside a for loop) which is invoked as thread1
  3. Execute command1 on session_handle2 (wrapped inside a for loop) which is invoked as thread2
  4. To break out of the LOOP when a particular state of the device is achieved (which is found by parsing the command output).

Issue: though break command is used inside a FOR LOOP, I see an error message in Execution Issues window saying:

“Illegal action break; BREAK is only valid inside a loop: for, foreach, while.

 

Looks like, the command break is not supported when the for loop is invoked as a thread. Is there any way to step out of the loop on a certain condition of the response?

 

Code Snippet Used:

for  i=0; i < 10; incr i

{

            command    SESSION_HANDLE  command_name

             analysis rule to check whether a certain part of the output is as EXPECTED

            if  $output != “expected”

               then

                  sleep 2 (checks for the Recovery of the device every 2s and for a maximum of 20s)

              else

                  break (On recovery of the device well within 20s, just step out of the loop)

}

The same successfully breaks out from the loop if the loop is not invoked as a thread. But, if I use that method, then I will not be able to run the next command parallely until the WAIT logic on the first thread completes.

 

Please let me know if there is any alternative way to go ahead with this kind of implementation.

 

 

Thanks

Ashwini

Expert
KumarS
Posts: 2,233
Registered: 08-30-2008
0

Re: BREAK command does not work when the LOOP is invoked as a thread

This seems like a bug. You could try the following:

 

create a comment step before the for loop. Select the for step and make it child step of the comment step. Then make the comment step asynchronous instead of the for step. If it works, you can use this as a workaround for now.

Community Leader
PaulD
Posts: 1,214
Registered: 09-02-2008
0

Re: BREAK command does not work when the LOOP is invoked as a thread

Or you could simply change the "break" to "return".  In this example, there are no additional instructions to execute in this secondary thread anyway.  So these should be equivalent.