You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by ni...@apache.org on 2021/08/12 15:12:24 UTC
[lucenenet] branch master updated: BUG: Fixed several tests that
were still using Environment.TickCount. TestSearcherManager was using it in
combination with Time.NanoTime() / Time.MillisecondsPerNanosecond which
caused the test to run forever.
This is an automated email from the ASF dual-hosted git repository.
nightowl888 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/lucenenet.git
The following commit(s) were added to refs/heads/master by this push:
new bd31fa5 BUG: Fixed several tests that were still using Environment.TickCount. TestSearcherManager was using it in combination with Time.NanoTime() / Time.MillisecondsPerNanosecond which caused the test to run forever.
bd31fa5 is described below
commit bd31fa50f0981c211b6ee8b6f533e737dfbd326b
Author: Shad Storhaug <sh...@shadstorhaug.com>
AuthorDate: Thu Aug 12 21:21:41 2021 +0700
BUG: Fixed several tests that were still using Environment.TickCount. TestSearcherManager was using it in combination with Time.NanoTime() / Time.MillisecondsPerNanosecond which caused the test to run forever.
---
src/Lucene.Net.Tests/Index/TestDeletionPolicy.cs | 6 +++---
src/Lucene.Net.Tests/Search/TestSearchWithThreads.cs | 8 ++++----
src/Lucene.Net.Tests/Search/TestSearcherManager.cs | 2 +-
3 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/src/Lucene.Net.Tests/Index/TestDeletionPolicy.cs b/src/Lucene.Net.Tests/Index/TestDeletionPolicy.cs
index 1d61b4e..9f8de66 100644
--- a/src/Lucene.Net.Tests/Index/TestDeletionPolicy.cs
+++ b/src/Lucene.Net.Tests/Index/TestDeletionPolicy.cs
@@ -273,7 +273,7 @@ namespace Lucene.Net.Index
IndexWriter writer = new IndexWriter(dir, conf);
ExpirationTimeDeletionPolicy policy = (ExpirationTimeDeletionPolicy)writer.Config.IndexDeletionPolicy;
IDictionary<string, string> commitData = new Dictionary<string, string>();
- commitData["commitTime"] = Convert.ToString(Environment.TickCount);
+ commitData["commitTime"] = Convert.ToString(J2N.Time.NanoTime() / J2N.Time.MillisecondsPerNanosecond); // LUCENENET: Use NanoTime() rather than CurrentTimeMilliseconds() for more accurate/reliable results
writer.SetCommitData(commitData);
writer.Commit();
writer.Dispose();
@@ -284,7 +284,7 @@ namespace Lucene.Net.Index
{
// Record last time when writer performed deletes of
// past commits
- lastDeleteTime = Environment.TickCount;
+ lastDeleteTime = J2N.Time.NanoTime() / J2N.Time.MillisecondsPerNanosecond; // LUCENENET: Use NanoTime() rather than CurrentTimeMilliseconds() for more accurate/reliable results
conf = NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random)).SetOpenMode(OpenMode.APPEND).SetIndexDeletionPolicy(policy);
mp = conf.MergePolicy;
mp.NoCFSRatio = 1.0;
@@ -295,7 +295,7 @@ namespace Lucene.Net.Index
AddDoc(writer);
}
commitData = new Dictionary<string, string>();
- commitData["commitTime"] = Convert.ToString(Environment.TickCount);
+ commitData["commitTime"] = Convert.ToString(J2N.Time.NanoTime() / J2N.Time.MillisecondsPerNanosecond); // LUCENENET: Use NanoTime() rather than CurrentTimeMilliseconds() for more accurate/reliable results
writer.SetCommitData(commitData);
writer.Commit();
writer.Dispose();
diff --git a/src/Lucene.Net.Tests/Search/TestSearchWithThreads.cs b/src/Lucene.Net.Tests/Search/TestSearchWithThreads.cs
index 3639461..888eda0 100644
--- a/src/Lucene.Net.Tests/Search/TestSearchWithThreads.cs
+++ b/src/Lucene.Net.Tests/Search/TestSearchWithThreads.cs
@@ -61,7 +61,7 @@ namespace Lucene.Net.Search
#endif
Random, dir);
- long startTime = Environment.TickCount;
+ long startTime = J2N.Time.NanoTime() / J2N.Time.MillisecondsPerNanosecond; // LUCENENET: Use NanoTime() rather than CurrentTimeMilliseconds() for more accurate/reliable results
// TODO: replace w/ the @nightly test data; make this
// into an optional @nightly stress test
@@ -84,7 +84,7 @@ namespace Lucene.Net.Search
IndexReader r = w.GetReader();
w.Dispose();
- long endTime = Environment.TickCount;
+ long endTime = J2N.Time.NanoTime() / J2N.Time.MillisecondsPerNanosecond; // LUCENENET: Use NanoTime() rather than CurrentTimeMilliseconds() for more accurate/reliable results
if (Verbose)
{
Console.WriteLine("BUILD took " + (endTime - startTime));
@@ -146,8 +146,8 @@ namespace Lucene.Net.Search
{
long totHits = 0;
long totSearch = 0;
- long stopAt = Environment.TickCount + outerInstance.RUN_TIME_MSEC;
- while (Environment.TickCount < stopAt && !failed)
+ long stopAt = (J2N.Time.NanoTime() / J2N.Time.MillisecondsPerNanosecond) + outerInstance.RUN_TIME_MSEC; // LUCENENET: Use NanoTime() rather than CurrentTimeMilliseconds() for more accurate/reliable results
+ while (J2N.Time.NanoTime() / J2N.Time.MillisecondsPerNanosecond < stopAt && !failed) // LUCENENET: Use NanoTime() rather than CurrentTimeMilliseconds() for more accurate/reliable results
{
s.Search(new TermQuery(new Term("body", "aaa")), col);
totHits += col.TotalHits;
diff --git a/src/Lucene.Net.Tests/Search/TestSearcherManager.cs b/src/Lucene.Net.Tests/Search/TestSearcherManager.cs
index 11f2990..b072646 100644
--- a/src/Lucene.Net.Tests/Search/TestSearcherManager.cs
+++ b/src/Lucene.Net.Tests/Search/TestSearcherManager.cs
@@ -149,7 +149,7 @@ namespace Lucene.Net.Search
Console.WriteLine("[" + Thread.CurrentThread.Name + "]: launch reopen thread");
}
- while (Environment.TickCount < stopTime)
+ while (J2N.Time.NanoTime() / J2N.Time.MillisecondsPerNanosecond < stopTime) // LUCENENET: Use NanoTime() rather than CurrentTimeMilliseconds() for more accurate/reliable results
{
Thread.Sleep(TestUtil.NextInt32(Random, 1, 100));
outerInstance.m_writer.Commit();