NightOwl888 commented on code in PR #838: URL: https://github.com/apache/lucenenet/pull/838#discussion_r1174448613
########## src/Lucene.Net.Tests.Facet/Taxonomy/TestTaxonomyCombined.cs: ########## @@ -784,7 +784,6 @@ public virtual void TestChildrenArraysGrowth() // Test that getParentArrays is valid when retrieved during refresh [Test] - [Slow] Review Comment: I have been using 4 seconds on my machine as a minimum for what is considered a slow test. This is actually right on the edge after the above updates, so this could go either way. ########## src/Lucene.Net.Tests.Facet/SlowRAMDirectory.cs: ########## @@ -80,7 +80,20 @@ internal virtual void DoSleep(Random random, int length) try { - Thread.Sleep(sTime); + // LUCENENET specific - timer resolution on windows by default is 15ms and small sleeps will end up taking + // 15ms instead causing certain tests to run slowly. Instead, we'll use a Stopwatch to get more accurate + if (sTime > MINIMUM_SUPPORTED_THREAD_SLEEP_TIME) Review Comment: Good work finding this cause! However, the resolution of `Stopwatch` varies depending on the OS, so we cannot use a constant for this. I used ChatGPT to come up with a solution that 1. Doesn't allocate a `Stopwatch` instance 2. Doesn't block the CPU 3. Correctly calculates the number of ticks to wait for the current platform 4. Can be used as a drop-in replacement for `Thread.Sleep()` in this instance ```c# internal virtual void DoSleep(Random random, int length) { int sTime = length < 10 ? sleepMillis : (int)(sleepMillis * Math.Log(length)); if (random != null) { sTime = random.Next(sTime); } try { Sleep(sTime); } catch (Exception ie) when (ie.IsInterruptedException()) { throw new Util.ThreadInterruptedException(ie); } } internal static void Sleep(int milliseconds) { long ticks = (long)((Stopwatch.Frequency / (double)1000) * milliseconds); // ticks per millisecond * milliseconds = total delay ticks long initialTick = Stopwatch.GetTimestamp(); long targetTick = initialTick + ticks; while (Stopwatch.GetTimestamp() < targetTick) { Thread.SpinWait(1); } } ``` On my system this branch takes at least 6 seconds to run `TestTaxonomyReaderRefreshRaces()`, but with these changes it drops to 4 or 5 seconds. I confirmed that the CPU is not pegged at 100% when `Sleep()` runs, but I haven't done any testing other than on Windows. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@lucenenet.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org