Forum Discussion

ccdssv1's avatar
ccdssv1
Contributor
13 years ago

Abort the curent running testStep from groovy

Hi,

I have a problem with abort/cancel a testStep execution from groovy scripts.

Normal when a testRunner is start, the script will not go to next step until the execution is completed, but running the testStep in a new thread I can pass over to the next step where I want to monitor the execution of this testStep, and in some conditions I will like to be able to abort this his execution (like we can from GUI), for example if the server don't response for a time of 3 seconds I will like to abort/cancel my execution. I know that we can set up the socket Timeout to stop the execution if the time pass over 3 seconds, but that is something different since this option will close the connection even if the server response, and in that case I will like the execution to continue until is finish.

To understand better what I want please fallow this is an scenario, I have an Rest call that will download a file, which for example take 9 seconds. Now I want to monitor the connection and if the server don't respond at any given time for more that 3 seconds I want to abort the Rest call execution. If I go and set up the Socket Time out to 3 seconds, my file will never finish to download since the connection is close 3 seconds after the call was send. I think that what I need is setUp the response time out, but I'm not aware of this option at general level or testStep level in SoapUI.

The effect of this issue is that if I reach in this state (the server don't respond for period if time, and I can't manually cancel) that testStep will never end and so will not go to my Rest call. To reproduce this start an http call, let the server to start responding to your call and then unplug the network cable, the testStep will remain on running mode until you close the soapUI application.

I try ed using the testRunner.cancel() but this don't stop the execution of the current running step, this will actual stop the runner to go to the next testStep (as can be seen in the below example). Looking with debug info logs what happen when abort is perform from UI I seen that is close the Socket, but how can I do that from a script?

myCode:

def runThread = Thread.start {
//Execute the Download step
log.info "Start running the testStep in a new thread"
runner = testRunner.runTestStepByName("Copy of [API]Download - get the file2")
//runner.getStatus()
log.info "Closing the testStep thread"
}
sleep 500
log.info runThread.getState()
while (runThread.getState().toString().equals("RUNNABLE")) {
log.info "TestStep thread is still running"
sleep 3000
testRunner.cancel("Abord testStep Running!")
log.info testRunner.getStatus()
}


Output:
Mon Feb 11 11:33:52 EET 2013:INFO:Start running the testStep in a new thread
Mon Feb 11 11:33:52 EET 2013:INFO:RUNNABLE
Mon Feb 11 11:33:52 EET 2013:INFO:TestStep thread is still running
Mon Feb 11 11:33:55 EET 2013:INFO:Canceled with reason [Abord testStep Running!]
Mon Feb 11 11:33:55 EET 2013:INFO:CANCELED
Mon Feb 11 11:33:55 EET 2013:INFO:TestStep thread is still running
Mon Feb 11 11:33:58 EET 2013:INFO:Canceled with reason [Abord testStep Running!]
Mon Feb 11 11:33:58 EET 2013:INFO:CANCELED
Mon Feb 11 11:33:58 EET 2013:INFO:TestStep thread is still running
Mon Feb 11 11:34:00 EET 2013:INFO:Closing the testStep thread
Mon Feb 11 11:34:01 EET 2013:INFO:Canceled with reason [Abord testStep Running!]
Mon Feb 11 11:34:01 EET 2013:INFO:CANCELED
Mon Feb 11 11:34:01 EET 2013:INFO:Main function Done..waitng for thread to finish


Thanks,
Ovidiu
No RepliesBe the first to reply