public virtual void TestModifyResolution() { try { // increase and test uint resolution = 20 * TimeLimitingCollector.DEFAULT_RESOLUTION; //400 TimeLimitingCollector.SetResolution(resolution); Assert.AreEqual(resolution, TimeLimitingCollector.GetResolution()); DoTestTimeout(false, true); // decrease much and test resolution = 5; TimeLimitingCollector.SetResolution(resolution); Assert.AreEqual(resolution, TimeLimitingCollector.GetResolution()); DoTestTimeout(false, true); // return to default and test resolution = TimeLimitingCollector.DEFAULT_RESOLUTION; TimeLimitingCollector.SetResolution(resolution); Assert.AreEqual(resolution, TimeLimitingCollector.GetResolution()); DoTestTimeout(false, true); } finally { TimeLimitingCollector.SetResolution(TimeLimitingCollector.DEFAULT_RESOLUTION); } }
private long MaxTime(bool multiThreaded) { long res = 2 * TimeLimitingCollector.GetResolution() + TIME_ALLOWED + SLOW_DOWN; // some slack for less noise in this test if (multiThreaded) { res = (long)(res * MULTI_THREAD_SLACK); // larger slack } return(res); }
private void DoTestTimeout(bool multiThreaded, bool greedy) { // setup MyHitCollector myHc = new MyHitCollector(this); myHc.SetSlowDown(SLOW_DOWN); Collector tlCollector = CreateTimedCollector(myHc, TIME_ALLOWED, greedy); // search TimeExceededException timoutException = null; try { Search(tlCollector); } catch (TimeExceededException x) { timoutException = x; } catch (System.Exception e) { Assert.IsTrue(false, "Unexpected exception: " + e); //==fail } // must get exception Assert.IsNotNull(timoutException, "Timeout expected!"); // greediness affect last doc collected int exceptionDoc = timoutException.GetLastDocCollected(); int lastCollected = myHc.GetLastDocCollected(); Assert.IsTrue(exceptionDoc > 0, "doc collected at timeout must be > 0!"); if (greedy) { Assert.IsTrue(exceptionDoc == lastCollected, "greedy=" + greedy + " exceptionDoc=" + exceptionDoc + " != lastCollected=" + lastCollected); Assert.IsTrue(myHc.HitCount() > 0, "greedy, but no hits found!"); } else { Assert.IsTrue(exceptionDoc > lastCollected, "greedy=" + greedy + " exceptionDoc=" + exceptionDoc + " not > lastCollected=" + lastCollected); } // verify that elapsed time at exception is within valid limits Assert.AreEqual(timoutException.GetTimeAllowed(), TIME_ALLOWED); // a) Not too early Assert.IsTrue(timoutException.GetTimeElapsed() > TIME_ALLOWED - TimeLimitingCollector.GetResolution(), "elapsed=" + timoutException.GetTimeElapsed() + " <= (allowed-resolution)=" + (TIME_ALLOWED - TimeLimitingCollector.GetResolution())); // b) Not too late. // This part is problematic in a busy test system, so we just print a warning. // We already verified that a timeout occurred, we just can't be picky about how long it took. if (timoutException.GetTimeElapsed() > MaxTime(multiThreaded)) { System.Console.Out.WriteLine("Informative: timeout exceeded (no action required: most probably just " + " because the test machine is slower than usual): " + "lastDoc=" + exceptionDoc + " ,&& allowed=" + timoutException.GetTimeAllowed() + " ,&& elapsed=" + timoutException.GetTimeElapsed() + " >= " + MaxTimeStr(multiThreaded)); } }
private System.String MaxTimeStr(bool multiThreaded) { System.String s = "( " + "2*resolution + TIME_ALLOWED + SLOW_DOWN = " + "2*" + TimeLimitingCollector.GetResolution() + " + " + TIME_ALLOWED + " + " + SLOW_DOWN + ")"; if (multiThreaded) { s = MULTI_THREAD_SLACK + " * " + s; } return(MaxTime(multiThreaded) + " = " + s); }