Commons Lang
  1. Commons Lang
  2. LANG-111

[Lang] time unit tests fail on Sundays

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0
    • Fix Version/s: 2.0
    • Component/s: None
    • Labels:
      None
    • Environment:

      Operating System: other
      Platform: Other

      Description

      The time unit tests fail when run on a Sunday:

      test.time:
      [echo] Running time package tests ...
      [java] ...F.F................
      [java] Time: 4.394
      [java] There were 2 failures:
      [java] 1)
      testParse(org.apache.commons.lang.time.CalendarUtilsTest)junit.framework.AssertionFailedError:
      parse last Sunday expected Sun Apr 27 06:39:17 MST 2003 but got Sun Apr 20
      06:39:17 MST 2003
      [java] at
      org.apache.commons.lang.time.CalendarUtilsTest.assertEquals(CalendarUtilsTest.java:373)
      [java] at
      org.apache.commons.lang.time.CalendarUtilsTest.testParse(CalendarUtilsTest.java:243)
      [java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      [java] at
      sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      [java] at
      sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      [java] 2)
      testWeekIterator(org.apache.commons.lang.time.CalendarUtilsTest)junit.framework.AssertionFailedError:
      expected Mon Apr 28 00:00:00 MST 2003 but got Mon Apr 21 00:00:00 MST 2003
      [java] at
      org.apache.commons.lang.time.CalendarUtilsTest.assertEquals(CalendarUtilsTest.java:373)
      [java] at
      org.apache.commons.lang.time.CalendarUtilsTest.assertWeekIterator(CalendarUtilsTest.java:346)
      [java] at
      org.apache.commons.lang.time.CalendarUtilsTest.assertWeekIterator(CalendarUtilsTest.java:324)
      [java] at
      org.apache.commons.lang.time.CalendarUtilsTest.testWeekIterator(CalendarUtilsTest.java:284)
      [java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      [java] at
      sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      [java] at
      sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

      Looks to me like the unit test code is checking the value of Calendar.DATE, when
      it should be looking at Calendar.DAY_OF_WEEK (at line 237 and below) to decide
      whether to make adjustments for today==Sunday.

      When I fix this, testParse succeeds but testWeekIterator hangs at the statement
      it = CalendarUtils.getCalendarIterator(now, CalendarUtils.RANGE_WEEK_RELATIVE);

        Activity

        Hide
        Stephen Colebourne added a comment -

        All patches applied, plus many other changes in time package.
        Thanks for the patches.

        Show
        Stephen Colebourne added a comment - All patches applied, plus many other changes in time package. Thanks for the patches.
        Hide
        Phil Steitz added a comment -

        Created an attachment (id=6476)
        patch to run testWeekIterator in a loop over start days

        Show
        Phil Steitz added a comment - Created an attachment (id=6476) patch to run testWeekIterator in a loop over start days
        Hide
        Phil Steitz added a comment -

        I am attaching another patch to CalendarUtilsTest.java that runs
        testWeekIterator() in a loop, incrementing the reference date in a loop to hit
        all days of the week.

        This patch also fixes the error in the test identified above (Calendar.DATE
        should be Calendar.DAY_OF_WEEK) in two places.

        Applying this patch will cause the test to hang, since it exposes the
        CalendarUtils bug identified (and patched) by Mohan above. This bug causes
        getCalendarIterator(Calendar focus, int rangeStyle) to go into an infinite loop
        when focus is a Sunday and rangeStyle is RANGE_WEEK_RELATIVE. Mohan's patch to
        CalendarUtils handles the boundary cases. When it is applied, all tests,
        (including the loop addition) succeed.

        Show
        Phil Steitz added a comment - I am attaching another patch to CalendarUtilsTest.java that runs testWeekIterator() in a loop, incrementing the reference date in a loop to hit all days of the week. This patch also fixes the error in the test identified above (Calendar.DATE should be Calendar.DAY_OF_WEEK) in two places. Applying this patch will cause the test to hang, since it exposes the CalendarUtils bug identified (and patched) by Mohan above. This bug causes getCalendarIterator(Calendar focus, int rangeStyle) to go into an infinite loop when focus is a Sunday and rangeStyle is RANGE_WEEK_RELATIVE. Mohan's patch to CalendarUtils handles the boundary cases. When it is applied, all tests, (including the loop addition) succeed.
        Hide
        Mohan Kishore added a comment -

        Created an attachment (id=6081)
        DATE to DAY_OF_WEEK, in test-case and minor fix in CalendarUtils

        Show
        Mohan Kishore added a comment - Created an attachment (id=6081) DATE to DAY_OF_WEEK, in test-case and minor fix in CalendarUtils
        Hide
        Mohan Kishore added a comment -

        Just a note, the CalendarUtils.getCalendarIterator(now,
        CalendarUtils.RANGE_WEEK_RELATIVE) hangs irrespective of the changes to the
        test-case. i.e. it will always hang if run on a sunday.

        It is just getting highlighted as currently, the assert just ahead of it fails
        on sundays. Hence, either everything runs fine, or the (unrelated) assert in
        front of it fails.

        As suggested, there are 2 places currently which need to be
        Calendar.DAY_OF_WEEK and not DATE. The RANGE_WEEK_RELATIVE logic needs to be
        investigated.

        Show
        Mohan Kishore added a comment - Just a note, the CalendarUtils.getCalendarIterator(now, CalendarUtils.RANGE_WEEK_RELATIVE) hangs irrespective of the changes to the test-case. i.e. it will always hang if run on a sunday. It is just getting highlighted as currently, the assert just ahead of it fails on sundays. Hence, either everything runs fine, or the (unrelated) assert in front of it fails. As suggested, there are 2 places currently which need to be Calendar.DAY_OF_WEEK and not DATE. The RANGE_WEEK_RELATIVE logic needs to be investigated.

          People

          • Assignee:
            Unassigned
            Reporter:
            Phil Steitz
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development