Mule
  1. Mule
  2. MULE-4791

EventGroupTestCase.testCompareTo() fails intermittently

    Details

    • User impact:
      Low
    • Similar Issues:
      MULE-3670TextFileStoreTestCase fails intermittently
      MULE-4820Intermittent test failures: JmsRetrySanityAsynchronousTestCase
      MULE-4078Intermittent test failure: DefaultMuleContextTestCase
      MULE-2523XmlFilterFunctionalTestCase Failing Intermittently
      MULE-4819Intermittent test failures: JmsRetryTransactional* tests
      MULE-4077Intermittent test failure: UdpDynamicEPTestCase
      MULE-4075Intermittent test failure: JmxStatisticsAsyncTestCase
      MULE-4076Intermittent test failure: MockTestCase
      MULE-4818Intermittent test failures: LoanBrokerEsn*ExampleTestCase
      MULE-4253ServiceInFlightMessagesJMSTestCase testInFlightStopPersistentMessagesPausedService and testInFlightStopPersistentMessages fail intermittently

      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);
      

        Issue Links

          Activity

          Hide
          Dirk Olmes added a comment -

          Edu, your analysis is spot on. This is already fixed in the 3.x sources, I added a small sleep between the two invocations. I'm not sure if the yield will help - this test runs single-threaded. The javadocs of Thread.yield() don't give me enough details to be sure that this is a good fix for the problem. Rather, port the fix from the 3.x tree back to 2.2.x.

          Show
          Dirk Olmes added a comment - Edu, your analysis is spot on. This is already fixed in the 3.x sources, I added a small sleep between the two invocations. I'm not sure if the yield will help - this test runs single-threaded. The javadocs of Thread.yield() don't give me enough details to be sure that this is a good fix for the problem. Rather, port the fix from the 3.x tree back to 2.2.x.
          Hide
          Edu Pereda added a comment -

          Ok, I will do that. I used Thread.yieald() because I thought there must always be another thread (at least the garbage collector one, for example), but to make sure, and for consistency, I will use what you suggested.

          Show
          Edu Pereda added a comment - Ok, I will do that. I used Thread.yieald() because I thought there must always be another thread (at least the garbage collector one, for example), but to make sure, and for consistency, I will use what you suggested.
          Hide
          Edu Pereda added a comment -
          Show
          Edu Pereda added a comment - This is the fisheye: http://fisheye.codehaus.org/changelog/mule/?cs=16850

            People

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

              Dates

              • Created:
                Updated:
                Resolved:

                Development