You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by er...@apache.org on 2018/09/07 02:55:28 UTC

lucene-solr:branch_7x: SOLR-12732: TestLogWatcher failure on Jenkins

Repository: lucene-solr
Updated Branches:
  refs/heads/branch_7x 7715bd02e -> dd2f85f01


SOLR-12732: TestLogWatcher failure on Jenkins

(cherry picked from commit 9e04375dc193d3815e9d755514a960f902c60cd2)


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/dd2f85f0
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/dd2f85f0
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/dd2f85f0

Branch: refs/heads/branch_7x
Commit: dd2f85f011277a1d1170838120d9c7b7c8f34ebc
Parents: 7715bd0
Author: Erick Erickson <Er...@gmail.com>
Authored: Thu Sep 6 19:25:33 2018 -0700
Committer: Erick Erickson <Er...@gmail.com>
Committed: Thu Sep 6 19:33:42 2018 -0700

----------------------------------------------------------------------
 solr/CHANGES.txt                                |  2 +
 .../org/apache/solr/logging/TestLogWatcher.java | 40 +++++++++++++-------
 2 files changed, 29 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/dd2f85f0/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 5700693..0acc5aa 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -268,6 +268,8 @@ Bug Fixes
 
 * SOLR-12733: SolrMetricReporterTest failure (Erick Erickson, David Smiley)
 
+* SOLR-12732: TestLogWatcher failure on Jenkins (Erick Erickson)
+
 Optimizations
 ----------------------
 

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/dd2f85f0/solr/core/src/test/org/apache/solr/logging/TestLogWatcher.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/logging/TestLogWatcher.java b/solr/core/src/test/org/apache/solr/logging/TestLogWatcher.java
index 658bc34..a93a11b 100644
--- a/solr/core/src/test/org/apache/solr/logging/TestLogWatcher.java
+++ b/solr/core/src/test/org/apache/solr/logging/TestLogWatcher.java
@@ -39,37 +39,51 @@ public class TestLogWatcher extends SolrTestCaseJ4 {
   // Create several log watchers and ensure that new messages go to the new watcher.
   @Test
   public void testLog4jWatcher() {
-    LogWatcher watcher = null;
+    LogWatcher watcher;
     int lim = random().nextInt(3) + 2;
     for (int idx = 0; idx < lim; ++idx) {
       String msg = "This is a test message: " + idx;
       watcher = LogWatcher.newRegisteredLogWatcher(config, null);
 
       // First ensure there's nothing in the new watcher.
-      assertEquals(-1, watcher.getLastEvent());
+
+      // Every time you put a message in the queue, you wait for it to come out _before_ creating
+      // a new watcher so it should be fine.
+      if (looper(watcher, null) == false) {
+        fail("There should be no messages when a new watcher finally gets registered! In loop: " + idx);
+      }
 
       // Now log a message and ensure that the new watcher sees it.
       log.warn(msg);
 
       // Loop to give the logger time to process the async message and notify the new watcher.
-      boolean foundMsg = false;
-      // In local testing this loop usually succeeds 1-2 tries.
-      for (int msgIdx = 0; msgIdx < 100; ++msgIdx) {
+      if (looper(watcher, msg) == false) {
+        fail("Should have found message " + msg + ". In loop: " + idx);
+      }
+    }
+  }
+  private boolean looper(LogWatcher watcher, String msg) {
+    // In local testing this loop usually succeeds 1-2 tries.
+    boolean success = false;
+    boolean testingNew = msg == null;
+    for (int msgIdx = 0; msgIdx < 100 && success == false; ++msgIdx) {
+      if (testingNew) { // check that there are no entries registered for the watcher
+        success = watcher.getLastEvent() == -1;
+      } else { // check that the expected message is there.
         // Returns an empty (but non-null) list even if there are no messages yet.
         SolrDocumentList events = watcher.getHistory(-1, new AtomicBoolean());
         for (SolrDocument doc : events) {
           if (doc.get("message").equals(msg)) {
-            foundMsg = true;
-            break;
+            success = true;
           }
         }
-        try {
-          Thread.sleep(10);
-        } catch (InterruptedException ie) {
-          ;
-        }
       }
-      assertTrue("Should have found message " + msg + " in loop: " + idx, foundMsg);
+      try {
+        Thread.sleep(10);
+      } catch (InterruptedException ie) {
+        ;
+      }
     }
+    return success;
   }
 }