Forum Discussion

M_McDonald's avatar
M_McDonald
Super Contributor
16 years ago

How to interrupt Groovy script when cancelling test case

In a test case I have a Groovy script that runs a loop checking for the existence of a file. I find that stopping the test case does not interrupt the Groovy script which continues to run.

Is there a property I can check to see if the test case has been canceled so the Groovy script can stop itself?
  • M_McDonald's avatar
    M_McDonald
    Super Contributor
    OK, I found testRunner.status which has a value of 'CANCELED' after canceling the test case:


    def timeout = 10000
    def elapsedTime = 0
    def increment = 1000

    while (testRunner.status.toString() != 'CANCELED' && elapsedTime < timeout ) {
    sleep(increment)
    elapsedTime += increment
    log.info "Elapsed time = $elapsedTime and TestRunner status = $testRunner.status"
    }

    log.info "All done"


    Log:

    Mon Mar 15 11:14:55 EDT 2010:INFO:Elapsed time = 1000 and TestRunner status = RUNNING
    Mon Mar 15 11:14:56 EDT 2010:INFO:Elapsed time = 2000 and TestRunner status = RUNNING
    Mon Mar 15 11:14:57 EDT 2010:INFO:Elapsed time = 3000 and TestRunner status = RUNNING
    Mon Mar 15 11:14:58 EDT 2010:INFO:Elapsed time = 4000 and TestRunner status = CANCELED
    Mon Mar 15 11:14:58 EDT 2010:INFO:All done