You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by aa...@apache.org on 2012/09/16 17:09:16 UTC

svn commit: r1385281 - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne: access/NestedDataContextPeerEventsTest.java unit/util/ThreadedTestHelper.java

Author: aadamchik
Date: Sun Sep 16 15:09:16 2012
New Revision: 1385281

URL: http://svn.apache.org/viewvc?rev=1385281&view=rev
Log:
increasing test wait interval to accommodate slower test servers

Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/NestedDataContextPeerEventsTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/util/ThreadedTestHelper.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/NestedDataContextPeerEventsTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/NestedDataContextPeerEventsTest.java?rev=1385281&r1=1385280&r2=1385281&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/NestedDataContextPeerEventsTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/NestedDataContextPeerEventsTest.java Sun Sep 16 15:09:16 2012
@@ -63,7 +63,7 @@ public class NestedDataContextPeerEvents
                 assertFalse(a2.getObjectId().isTemporary());
                 assertEquals(a2.getObjectId(), a1.getObjectId());
             }
-        }.assertWithTimeout(1000);
+        }.assertWithTimeout(2000);
     }
 
     public void testPeerObjectUpdatedSimpleProperty() throws Exception {
@@ -91,7 +91,7 @@ public class NestedDataContextPeerEvents
                         "Peer data context became dirty on event processing",
                         peer2.hasChanges());
             }
-        }.assertWithTimeout(1000);
+        }.assertWithTimeout(2000);
 
     }
 
@@ -131,7 +131,7 @@ public class NestedDataContextPeerEvents
                         "Peer data context became dirty on event processing",
                         peer2.hasChanges());
             }
-        }.assertWithTimeout(1000);
+        }.assertWithTimeout(2000);
 
     }
 
@@ -175,7 +175,7 @@ public class NestedDataContextPeerEvents
                         "Peer data context became dirty on event processing",
                         peer2.hasChanges());
             }
-        }.assertWithTimeout(1000);
+        }.assertWithTimeout(2000);
 
     }
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/util/ThreadedTestHelper.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/util/ThreadedTestHelper.java?rev=1385281&r1=1385280&r2=1385281&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/util/ThreadedTestHelper.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/util/ThreadedTestHelper.java Sun Sep 16 15:09:16 2012
@@ -17,62 +17,62 @@
  *  under the License.
  ****************************************************************/
 
-
 package org.apache.cayenne.unit.util;
 
 /**
- * Helper class allowing unit tests to wait till a code in question
- * executes in a separate thread. There is still some element of uncertainty remains,
- * since this implementation simply tries to give other threads enough time to execute,
- * instead of watching for threads activity. 
+ * Helper class allowing unit tests to wait till a code in question executes in
+ * a separate thread. There is still some element of uncertainty remains, since
+ * this implementation simply tries to give other threads enough time to
+ * execute, instead of watching for threads activity.
  * 
- * <p>Note that result sampling is done every 300 ms., so if the test succeeds earlier,
- * test case wouldn't have to wait for the whole time period specified by timeout.</p>
+ * <p>
+ * Note that result sampling is done every 300 ms., so if the test succeeds
+ * earlier, test case wouldn't have to wait for the whole time period specified
+ * by timeout.
+ * </p>
  * 
  */
 public abstract class ThreadedTestHelper {
 
-    protected abstract void assertResult() throws Exception;
+	protected abstract void assertResult() throws Exception;
 
-    public void assertWithTimeout(long timeoutMs) throws Exception {
-        long checkEveryXMs;
-        int maxMumberOfChecks;
-
-        if (timeoutMs < 300) {
-            maxMumberOfChecks = 1;
-            checkEveryXMs = timeoutMs;
-        }
-        else {
-            maxMumberOfChecks = Math.round(timeoutMs / 300.00f);
-            checkEveryXMs = 300;
-        }
-
-        // TODO: for things asserting that a certain event DID NOT happen
-        // we need a better implementation, that should probably sleep for 
-        // the whole timeout interval, since otherwise we may have a false
-        // positive (i.e. assertion succeeded not because a certain thing did not
-        // happen, but rather cause it happened after the assertion was run).
-
-        // for now lets wait for at least one time slice to decrease 
-        // the possibility of false positives
-        Thread.sleep(checkEveryXMs);
-        maxMumberOfChecks--;
-
-        // wait 5 seconds at the most (10 times 0.5 sec.)
-        for (int i = 0; i < maxMumberOfChecks; i++) {
-            try {
-                assertResult();
-
-                // success... return immediately
-                return;
-            }
-            catch (Throwable th) {
-                // wait some more
-                Thread.sleep(checkEveryXMs);
-            }
-        }
-
-        // if it throws, it throws...
-        assertResult();
-    }
+	public void assertWithTimeout(long timeoutMs) throws Exception {
+		long checkEveryXMs;
+		int maxMumberOfChecks;
+
+		if (timeoutMs < 300) {
+			maxMumberOfChecks = 1;
+			checkEveryXMs = timeoutMs;
+		} else {
+			maxMumberOfChecks = Math.round(timeoutMs / 300.00f);
+			checkEveryXMs = 300;
+		}
+
+		// TODO: for things asserting that a certain event DID NOT happen
+		// we need a better implementation, that should probably sleep for
+		// the whole timeout interval, since otherwise we may have a false
+		// positive (i.e. assertion succeeded not because a certain thing did
+		// not happen, but rather cause it happened after the assertion was
+		// run).
+
+		// for now lets wait for at least one time slice to decrease
+		// the possibility of false positives
+		Thread.sleep(checkEveryXMs);
+		maxMumberOfChecks--;
+
+		for (int i = 0; i < maxMumberOfChecks; i++) {
+			try {
+				assertResult();
+
+				// success... return immediately
+				return;
+			} catch (Throwable th) {
+				// wait some more
+				Thread.sleep(checkEveryXMs);
+			}
+		}
+
+		// if it throws, it throws...
+		assertResult();
+	}
 }