[dna-commits] DNA SVN: r1401 - trunk/dna-jcr/src/test/java/org/jboss/dna/jcr.

dna-commits at lists.jboss.org dna-commits at lists.jboss.org
Fri Dec 4 02:38:49 EST 2009


Author: rhauch
Date: 2009-12-04 02:38:49 -0500 (Fri, 04 Dec 2009)
New Revision: 1401

Modified:
   trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrObservationManagerTest.java
Log:
DNA-456 The build failed again in JcrObservationManagerTest, and so I re-ran the tests about 10x before I got the failure locally.  After some debugging, I noticed that when it failed, all of the missing events appear to be the last event, so I poked around the TestListener.waitForEvents() method, which calls 'await(...)' on a CountDownLatch that is decremented in the 'onEvent(...)' method.  The 'latch.countDown()' method was being called (and potentially the 'waitForEvents()' method returning) immediately after 'itr.nextEvent()' and before the event was added to the TestListener's state.  Of course, whether the 'waitForEvents()' method returns before or after the event info is added depends completely on thread scheduling.  This would explain how it frequently worked on some machines but frequently failed on others.

I put the whole content of the while loop in the 'onEvent(...)' method in a try-finally block, and moved the 'latch.countDown()' method to the finally.  I ran several tests locally with no failures, but I'll commit to see if they pass on the build box.

Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrObservationManagerTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrObservationManagerTest.java	2009-12-04 06:56:40 UTC (rev 1400)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrObservationManagerTest.java	2009-12-04 07:38:49 UTC (rev 1401)
@@ -1683,24 +1683,27 @@
             // iterator position must be set initially zero
             if (position == 0) {
                 while (itr.hasNext()) {
-                    this.latch.countDown();
-                    Event event = itr.nextEvent();
+                    try {
+                        Event event = itr.nextEvent();
+                        // check iterator position
+                        if (++position != itr.getPosition()) {
+                            this.errorMessage = "EventIterator position was " + itr.getPosition() + " and should be " + position;
+                            break;
+                        }
 
-                    // check iterator position
-                    if (++position != itr.getPosition()) {
-                        this.errorMessage = "EventIterator position was " + itr.getPosition() + " and should be " + position;
-                        break;
-                    }
+                        this.events.add(event);
+                        ++this.eventsProcessed;
 
-                    this.events.add(event);
-                    ++this.eventsProcessed;
+                        // check event type
+                        int eventType = event.getType();
 
-                    // check event type
-                    int eventType = event.getType();
-
-                    if ((this.eventTypes & eventType) == 0) {
-                        this.errorMessage = "Received a wrong event type of " + eventType;
-                        break;
+                        if ((this.eventTypes & eventType) == 0) {
+                            this.errorMessage = "Received a wrong event type of " + eventType;
+                            break;
+                        }
+                    } finally {
+                        // This has to be done LAST, otherwise waitForEvents() will return before the above stuff is done
+                        this.latch.countDown();
                     }
                 }
             } else {



More information about the dna-commits mailing list