Here's the patch:
{code}
Index: lucene/src/test/org/apache/lucene/search/TestSearchWithThreads.java
===================================================================
--- lucene/src/test/org/apache/lucene/search/TestSearchWithThreads.java
(revision 1044091)
+++ lucene/src/test/org/apache/lucene/search/TestSearchWithThreads.java
(working copy)
@@ -66,11 +66,10 @@
final IndexSearcher s = new IndexSearcher(r);
final AtomicBoolean failed = new AtomicBoolean();
- final long stopAt = System.currentTimeMillis() + RUN_TIME_MSEC;
final AtomicLong netSearch = new AtomicLong();
Thread[] threads = new Thread[NUM_SEARCH_THREADS];
- for(int threadID=0;threadID<NUM_SEARCH_THREADS;threadID++) {
+ for (int threadID = 0; threadID < NUM_SEARCH_THREADS; threadID++) {
threads[threadID] = new Thread() {
TotalHitCountCollector col = new TotalHitCountCollector();
@Override
@@ -78,6 +77,7 @@
try {
long totHits = 0;
long totSearch = 0;
+ long stopAt = System.currentTimeMillis() + RUN_TIME_MSEC;
while(System.currentTimeMillis() < stopAt && !failed.get()) {
s.search(new TermQuery(new Term("body", "aaa")), col);
totHits += col.getTotalHits();
@@ -85,7 +85,7 @@
totHits += col.getTotalHits();
totSearch++;
}
- assertTrue(totHits > 0);
+ assertTrue(totSearch > 0 && totHits > 0);
netSearch.addAndGet(totSearch);
} catch (Exception exc) {
failed.set(true);
@@ -94,12 +94,16 @@
}
};
threads[threadID].setDaemon(true);
- threads[threadID].start();
}
- for(int threadID=0;threadID<NUM_SEARCH_THREADS;threadID++) {
- threads[threadID].join();
+ for (Thread t : threads) {
+ t.start();
}
+
+ for (Thread t : threads) {
+ t.join();
+ }
+
if (VERBOSE) System.out.println(NUM_SEARCH_THREADS + " threads did " +
netSearch.get() + " searches");
s.close();
{code}
I intend to commit this and apply on 3x too.
Shai
On Thu, Dec 9, 2010 at 8:36 PM, Michael McCandless <
[email protected]> wrote:
> I think likely the failure was false -- if the machine is stressed,
> the last thread(s) may in fact do zero iterations through the while
> loop, and then the test falsely fails.
>
> Mike
>
> On Thu, Dec 9, 2010 at 1:31 PM, Robert Muir <[email protected]> wrote:
> > On Thu, Dec 9, 2010 at 11:05 AM, Michael McCandless
> > <[email protected]> wrote:
> >> Hmm why no repro command? That's no good. Maybe if a test fails only
> >> due to threads other than main, we fail to print repro?
> >>
> >
> > I fixed this in trunk: good catch... but i'm wishing we had Shai's
> > seed that he used to create the failure.
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [email protected]
> > For additional commands, e-mail: [email protected]
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>