Uploaded image for project: 'XWiki Platform'
  1. XWiki Platform
  2. XWIKI-24761

CommentsIT#commentsAreOrderedByDate fails when the test runner's timezone is not UTC

    XMLWordPrintable

Details

    • Unknown
    • N/A
    • N/A

    Description

      Problem

      CommentsIT#commentsAreOrderedByDate (in xwiki-platform-flamingo-skin-test-docker) fails on any machine whose default timezone is not UTC. On a Europe/Paris host every date assertion is off by one hour:

      expected: <1970/01/01 00:00> but was: <1970/01/01 01:00>
      

      Both parameterized cases (English and French date format) fail.

      The CI agents run in UTC, so the offset is zero there and the test passes. The failure is thus invisible to CI by construction and only ever hits developers running the test locally.

      Cause

      The test creates its XWiki.XWikiComments objects over REST, formatting each date property with:

      private static final SimpleDateFormat DEFAULT_DATE_FORMAT = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
      ...
      return DEFAULT_DATE_FORMAT.format(new Date(seconds * 1000L));
      

      That formatter has no timezone set, so it formats in the test runner's default timezone: getDateString(24) produces 01/01/1970 01:00:24 on a Europe/Paris host instead of 01/01/1970 00:00:24.

      The server then parses that string in DateClass.fromString(), which also sets no timezone and therefore parses in the server's timezone (UTC in the test container). Since the test sets the wiki timezone preference to UTC, the comment dates are displayed in UTC and the assertions expect UTC. The displayed dates are therefore shifted by the test runner's UTC offset.

      The wiki timezone preference is correctly applied to the display. Only the input side of the test is wrong.

      Fix

      Format the dates sent to the server in UTC, by replacing the host-zone SimpleDateFormat with a DateTimeFormatter pinned to ZoneOffset.UTC.

      Verified: both parameterized cases pass on a Europe/Paris host with the fix, and fail without it.

      Attachments

        Activity

          People

            vmassol Vincent Massol
            vmassol Vincent Massol
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: