Uploaded image for project: 'Derby'
  1. Derby
  2. DERBY-4624

Broken logic for avoiding testing across midnight in TimestampArithTest

Attach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 10.6.1.0
    • 10.7.1.1
    • Test
    • None

    Description

      TimestampArithTest's decorator has this code to avoid failures in case the test starts close to midnight:

      /*

      • Make sure that we are not so close to midnight that TODAY
      • might be yesterday before we are finished using it.
        */
        while (calendar.get(Calendar.HOUR) == 23
        && calendar.get(Calendar.MINUTE) >= 58)
        Unknown macro: { try { Thread.sleep((60 - calendar.get(Calendar.SECOND)) * 1000); } catch (InterruptedException ie) { // ignore it } }

      There are at least three problems with this code:

      1) (calendar.get(Calendar.HOUR) == 23) never evaluates to true, because calendar.get(Calendar.HOUR) returns values in the range 0-11. Calendar.HOUR_OF_DAY should be used instead.

      2) If the current time is after 23:58 and before 23:59, the code sleeps until 23:59, the test will wait until 23:59 before it starts, making it even more likely that it will cross midnight while running.

      3) The code is executed after the Calendar object has been initialized, so if this code is ever triggered and waits until after midnight, the TODAY field is guaranteed to be yesterday when the test starts executing.

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            knutanders Knut Anders Hatlen
            knutanders Knut Anders Hatlen
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment