Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-49046

WithTimeout Annotation does not work

    XMLWordPrintable

Details

    Description

      @WithTimeout does not work as expected. It will only affect the error text ("Test timed out (after 2 seconds)") rather than the timing of the test itself.

      eg, using the following test:

      public class WithTimeoutTest {
      
          @Rule
          public JenkinsRule jenkinsRule = new JenkinsRule();
      
          @WithTimeout(1)
          @Test
          public void testFailsAfter1Second() throws InterruptedException {
              Thread.sleep(181_000);
          }
      }

      Expected Result:

      • Test failed after 1 second.
      • log message: "Test timed out (after 5 seconds)".

      Actual Result:

      • Test failed after 180 seconds (JenkinsRule default)
      • log message: "Test timed out (after 5 seconds)".

      Attachments

        Activity

          The problem here is the value of JenkinsRule#timeout is read and acted upon before it is overridden. Fix proposed: https://github.com/jenkinsci/jenkins-test-harness/pull/107

          olivergondza Oliver Gondža added a comment - The problem here is the value of JenkinsRule#timeout is read and acted upon before it is overridden. Fix proposed: https://github.com/jenkinsci/jenkins-test-harness/pull/107
          jglick Jesse Glick added a comment -

          Sorry, I thought you were talking about JUnit’s Timeout rule. Yeah @WithTimeout ought to work if it is there. I do not recall ever using it though, and it is not tested, so perhaps it got broken at some point, most likely 2.25.

          jglick Jesse Glick added a comment - Sorry, I thought you were talking about JUnit’s  Timeout rule. Yeah @WithTimeout ought to work if it is there. I do not recall ever using it though, and it is not tested, so perhaps it got broken at some point, most likely 2.25.
          agentgonzo Steve Arch added a comment -   It's not supported? https://github.com/jenkinsci/jenkins-test-harness/blob/master/src/main/java/org/jvnet/hudson/test/recipes/WithTimeout.java#L67
          agentgonzo Steve Arch added a comment -

          jenkins-test-harness version 2.31

           

          agentgonzo Steve Arch added a comment - jenkins-test-harness version 2.31  
          jglick Jesse Glick added a comment -

          @WithTimeout is not supported. JenkinsRule uses the timeout mechanism internally. You should only use the timeout field.

          As requested on the dev list, please specify the version of jenkins-test-harness you are using.

          jglick Jesse Glick added a comment - @WithTimeout is not supported. JenkinsRule uses the timeout mechanism internally. You should only use the timeout field. As requested on the dev list, please specify the version of jenkins-test-harness you are using.

          Hi Steve,

          Well in our case neither works. With the approach suggested by you, the print in the log shows the changed value, however the test is still aborted in 3 mins. 
          Test timed out (after 1500 seconds).

          valeriefdes Valerie Fernandes added a comment - Hi Steve, Well in our case neither works. With the approach suggested by you, the print in the log shows the changed value, however the test is still aborted in 3 mins.  Test timed out (after 1500 seconds).
          agentgonzo Steve Arch added a comment - - edited

          As a workaround, if you are happy with all your tests using the same timeout, you can set it in the constructor (an @Before method does not work)

           

          public class WithTimeoutTest {
          
              @Rule
              public JenkinsRule jenkinsRule = new JenkinsRule();
          
              public WithTimeoutTest()
              {
                  jenkinsRule.timeout=1;
              }
          
              // @WithTimeout(1)
              @Test
              public void testFailsAfter1Second() throws InterruptedException {
                  Thread.sleep(181_000);
              }
          }
          agentgonzo Steve Arch added a comment - - edited As a workaround, if you are happy with all your tests using the same timeout, you can set it in the constructor (an @Before method does not work)   public class WithTimeoutTest { @Rule public JenkinsRule jenkinsRule = new JenkinsRule(); public WithTimeoutTest() { jenkinsRule.timeout=1; } // @WithTimeout(1) @Test public void testFailsAfter1Second() throws InterruptedException { Thread .sleep(181_000); } }

          People

            olivergondza Oliver Gondža
            agentgonzo Steve Arch
            Votes:
            2 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: