TimeoutException in test next to failed test with timeout #540

Closed
irb1s opened this Issue Jun 10, 2013 · 0 comments

Comments

Projects
None yet
1 participant
@irb1s

irb1s commented Jun 10, 2013

cucumber-JVM, ver.1.1.1 (but, I see the code caused the issue still in your repo)

How to reproduce:

  1. Create step with timeout & throw exception in it. e.g.
    @then(value="^I just fail$", timeout=5000)
    public void I_just_fail() throws Throwable {
    Assert.fail("Just fail")
    }
  2. Create several scenarios with one of them 'just fail'
  3. Get in test next (in fact, after 5sec) to failed test TimeoutException:

java.util.concurrent.TimeoutException: Timed out after 5000ms.
at cucumber.runtime.Timeout.timeout(Timeout.java:29)

The exception caused by scheduled task in static method cucumber.runtime.Timeout::timeout(Callback, int) which is not canceled in case if step throws exception (it interrupts current thread after timeout).
This patch solves the issue:

Index: core/src/main/java/cucumber/runtime/Timeout.java
<+>windows-1251
===================================================================
--- core/src/main/java/cucumber/runtime/Timeout.java    (date 1370818741000)
+++ core/src/main/java/cucumber/runtime/Timeout.java    (revision )
@@ -22,11 +22,12 @@
                 }
             }, timeoutMillis, TimeUnit.MILLISECONDS);
             try {
-                T result = callback.call();
-                timer.cancel(true);
-                return result;
+                return callback.call();
             } catch (InterruptedException timeout) {
                 throw new TimeoutException("Timed out after " + timeoutMillis + "ms.");
+            } finally {
+                done.set(true);
+                timer.cancel(true);
             }
         }
     }

@irb1s irb1s closed this Jun 10, 2013

@irb1s irb1s reopened this Jun 10, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment