You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by rm...@apache.org on 2011/07/24 16:42:55 UTC

svn commit: r1150385 - in /lucene/dev/branches/branch_3x: ./ lucene/ lucene/backwards/ lucene/backwards/src/test-framework/ lucene/backwards/src/test/ lucene/src/test-framework/org/apache/lucene/util/LuceneTestCase.java solr/

Author: rmuir
Date: Sun Jul 24 14:42:55 2011
New Revision: 1150385

URL: http://svn.apache.org/viewvc?rev=1150385&view=rev
Log:
SOLR-2673: randomize test methods in LuceneTestCase to flush out test-ordering dependencies

Modified:
    lucene/dev/branches/branch_3x/   (props changed)
    lucene/dev/branches/branch_3x/lucene/   (props changed)
    lucene/dev/branches/branch_3x/lucene/backwards/   (props changed)
    lucene/dev/branches/branch_3x/lucene/backwards/src/test/   (props changed)
    lucene/dev/branches/branch_3x/lucene/backwards/src/test-framework/   (props changed)
    lucene/dev/branches/branch_3x/lucene/src/test-framework/org/apache/lucene/util/LuceneTestCase.java
    lucene/dev/branches/branch_3x/solr/   (props changed)

Modified: lucene/dev/branches/branch_3x/lucene/src/test-framework/org/apache/lucene/util/LuceneTestCase.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/test-framework/org/apache/lucene/util/LuceneTestCase.java?rev=1150385&r1=1150384&r2=1150385&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/test-framework/org/apache/lucene/util/LuceneTestCase.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/test-framework/org/apache/lucene/util/LuceneTestCase.java Sun Jul 24 14:42:55 2011
@@ -224,12 +224,16 @@ public abstract class LuceneTestCase ext
   @Deprecated
   private static List<String> testClassesRun = new ArrayList<String>();
   
-  @BeforeClass
-  public static void beforeClassLuceneTestCaseJ4() {
-    state = State.INITIAL;
+  private static void initRandom() {
+    assert !random.initialized;
     staticSeed = "random".equals(TEST_SEED) ? seedRand.nextLong() : TwoLongs.fromString(TEST_SEED).l1;
     random.setSeed(staticSeed);
     random.initialized = true;
+  }
+
+  @BeforeClass
+  public static void beforeClassLuceneTestCaseJ4() {
+    state = State.INITIAL;
     tempDirs.clear();
     stores = Collections.synchronizedMap(new IdentityHashMap<MockDirectoryWrapper,StackTraceElement[]>());
     // enable this by default, for IDE consistency with ant tests (as its the default from ant)
@@ -1221,6 +1225,10 @@ public abstract class LuceneTestCase ext
     protected List<FrameworkMethod> computeTestMethods() {
       if (testMethods != null)
         return testMethods;
+      
+      initRandom();
+      Random r = new Random(random.nextLong());
+
       testClassesRun.add(getTestClass().getJavaClass().getSimpleName());
       testMethods = new ArrayList<FrameworkMethod>();
       for (Method m : getTestClass().getJavaClass().getMethods()) {
@@ -1270,6 +1278,15 @@ public abstract class LuceneTestCase ext
           } catch (Exception e) { throw new RuntimeException(e); }
         }
       }
+      // sort the test methods first before shuffling them, so that the shuffle is consistent
+      // across different implementations that might order the methods different originally.
+      Collections.sort(testMethods, new Comparator<FrameworkMethod>() {
+        @Override
+        public int compare(FrameworkMethod f1, FrameworkMethod f2) {
+          return f1.getName().compareTo(f2.getName());
+        }
+      });
+      Collections.shuffle(testMethods, r);
       return testMethods;
     }
 
@@ -1307,6 +1324,7 @@ public abstract class LuceneTestCase ext
 
     public LuceneTestCaseRunner(Class<?> clazz) throws InitializationError {
       super(clazz);
+      // evil we cannot init our random here, because super() calls computeTestMethods!!!!;
       Filter f = new Filter() {
 
         @Override