You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by en...@apache.org on 2018/12/17 20:56:27 UTC

[sling-org-apache-sling-jcr-contentloader] branch master updated: Attempt to stabilize intermittent test failures that happen due to the bundle content loading not being complete before the assertions happen.

This is an automated email from the ASF dual-hosted git repository.

enorman pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-contentloader.git


The following commit(s) were added to refs/heads/master by this push:
     new 892c1af  Attempt to stabilize intermittent test failures that happen due to the bundle content loading not being complete before the assertions happen.
892c1af is described below

commit 892c1af042297a322a6139e871951b8f54f77711
Author: Eric Norman <en...@apache.org>
AuthorDate: Mon Dec 17 12:56:21 2018 -0800

    Attempt to stabilize intermittent test failures that happen due to the
    bundle content loading not being complete before the assertions happen.
---
 .../contentloader/it/ContentloaderTestSupport.java | 40 +++++++++++++++++-----
 1 file changed, 32 insertions(+), 8 deletions(-)

diff --git a/src/test/java/org/apache/sling/jcr/contentloader/it/ContentloaderTestSupport.java b/src/test/java/org/apache/sling/jcr/contentloader/it/ContentloaderTestSupport.java
index 5bc7617..e5e5bca 100644
--- a/src/test/java/org/apache/sling/jcr/contentloader/it/ContentloaderTestSupport.java
+++ b/src/test/java/org/apache/sling/jcr/contentloader/it/ContentloaderTestSupport.java
@@ -18,11 +18,21 @@
  */
 package org.apache.sling.jcr.contentloader.it;
 
+import static org.apache.sling.testing.paxexam.SlingOptions.slingQuickstartOakTar;
+import static org.apache.sling.testing.paxexam.SlingOptions.slingResourcePresence;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+import static org.ops4j.pax.exam.CoreOptions.junitBundles;
+import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
+import static org.ops4j.pax.exam.cm.ConfigurationAdminOptions.newConfiguration;
+
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.Arrays;
 import java.util.Objects;
 import java.util.UUID;
+import java.util.concurrent.TimeUnit;
 
 import javax.inject.Inject;
 import javax.jcr.Session;
@@ -44,14 +54,6 @@ import org.osgi.framework.Constants;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import static org.apache.sling.testing.paxexam.SlingOptions.slingQuickstartOakTar;
-import static org.apache.sling.testing.paxexam.SlingOptions.slingResourcePresence;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.ops4j.pax.exam.CoreOptions.junitBundles;
-import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
-import static org.ops4j.pax.exam.cm.ConfigurationAdminOptions.newConfiguration;
-
 public abstract class ContentloaderTestSupport extends TestSupport {
 
     @Inject
@@ -88,6 +90,28 @@ public abstract class ContentloaderTestSupport extends TestSupport {
             final Bundle bundle = bundleContext.installBundle(bundleSymbolicName, is);
             bundle.start();
         }
+        
+		// stabilize the downstream assertions by waiting a moment for the background content loading 
+        // to be processed.  Retry the checking a few times (if necessary) since the timing is tricky.
+        String contentLoadedPath = String.format("/var/sling/bundle-content/%s", bundleSymbolicName);
+        long timeoutSeconds = 30;
+        long timeout = System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(timeoutSeconds);
+        boolean retry = true;
+        do {
+        	if (session.itemExists(contentLoadedPath)) {
+        		//stop looping
+        		retry = false;
+        	} else {
+        		if (System.currentTimeMillis() > timeout) {
+			        fail("RetryLoop failed, condition is false after " + timeoutSeconds + " seconds: " 
+			                + "A content loaded node expected at " + contentLoadedPath);
+        		} else {
+                    logger.warn("Bundle content not loaded yet, retrying after a short delay, path={}", contentLoadedPath);
+                    Thread.sleep(200);
+                    session.refresh(false);
+        		}        		
+        	}
+        } while (retry);        
     }
 
     @After