Uploaded image for project: 'Mule'
  1. Mule
  2. MULE-4791

EventGroupTestCase.testCompareTo() fails intermittently

    Details

    • User impact:
      Low
    • Similar Issues:

      Description

      The test EventGroupTestCase.testCompareTo() fails intermittently because it depends on the fact that some time passes between the creation of one object and the next.

      This is the affected code:

              // when the groupId is not Comparable, the creation time is used as fallback
              g1 = new EventGroup(new Object());
              g2 = new EventGroup(new Object());
              // g1 is older (smaller) than g2
              assertTrue(g1.compareTo(g2) < 0);
              assertTrue(g2.compareTo(g1) > 0);
      

      In order for the assertions to pass, there must be at least one nanosecond between the creation of g1 and g2. Sometimes this is not the case so the test fails. I suggest inserting a Thread.yield() call in the middle of the two cretions, like this:

              // when the groupId is not Comparable, the creation time is used as fallback
              g1 = new EventGroup(new Object());
              Thread.yield(); // this makes sure that there is a time difference between
                              // the two EventGroup creations.
              g2 = new EventGroup(new Object());
              // g1 is older (smaller) than g2
              assertTrue(g1.compareTo(g2) < 0);
              assertTrue(g2.compareTo(g1) > 0);
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                epere4 Edu Pereda
                Reporter:
                epere4 Edu Pereda
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Fix Release Date:
                  18/Aug/10