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
commit b446f84d5c7a2d71bc4a305b9ac78812cc57832a Author: Shad Storhaug <[email protected]> AuthorDate: Sat Aug 14 02:59:17 2021 +0700 BUG: Lucnene.Net.Tests.Index.TestDocumentsWriterStallControl: Changed to use Thread.Yield() instead of Thread.Sleep(0) to match Lucene. This was a workaround for .NET Standard 1.x that is no longer applicable. --- .../Index/TestDocumentsWriterStallControl.cs | 33 ++++++++++++---------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/src/Lucene.Net.Tests/Index/TestDocumentsWriterStallControl.cs b/src/Lucene.Net.Tests/Index/TestDocumentsWriterStallControl.cs index a592365..4f5dd18 100644 --- a/src/Lucene.Net.Tests/Index/TestDocumentsWriterStallControl.cs +++ b/src/Lucene.Net.Tests/Index/TestDocumentsWriterStallControl.cs @@ -83,7 +83,7 @@ namespace Lucene.Net.Index ctrl.UpdateStalled(false); if (Random.NextBoolean()) { - Thread.Sleep(0); + Thread.Yield(); } else { @@ -170,28 +170,28 @@ namespace Lucene.Net.Index AssertState(numReleasers, numStallers, numWaiters, threads, ctrl); } - checkPoint.Value = (false); + checkPoint.Value = false; sync.waiter.Signal(); sync.leftCheckpoint.Wait(); } Assert.IsFalse(checkPoint); Assert.AreEqual(0, sync.waiter.CurrentCount); - if (checkPointProbability >= (float)Random.NextDouble()) + if (checkPointProbability >= Random.NextSingle()) { sync.Reset(numStallers + numReleasers, numStallers + numReleasers + numWaiters); - checkPoint.Value = (true); + checkPoint.Value = true; } } if (!checkPoint) { sync.Reset(numStallers + numReleasers, numStallers + numReleasers + numWaiters); - checkPoint.Value = (true); + checkPoint.Value = true; } - Assert.IsTrue(sync.updateJoin.Wait(new TimeSpan(0, 0, 0, 10))); + Assert.IsTrue(sync.updateJoin.Wait(TimeSpan.FromSeconds(10))); AssertState(numReleasers, numStallers, numWaiters, threads, ctrl); - checkPoint.Value = (false); - stop.Value = (true); + checkPoint.Value = false; + stop.Value = true; sync.waiter.Signal(); sync.leftCheckpoint.Wait(); @@ -270,7 +270,7 @@ namespace Lucene.Net.Index { try { - Assert.IsTrue(sync.await()); + Assert.IsTrue(sync.Await()); } catch (Exception e) when (e.IsInterruptedException()) { @@ -325,7 +325,7 @@ namespace Lucene.Net.Index sync.updateJoin.Signal(); try { - Assert.IsTrue(sync.await()); + Assert.IsTrue(sync.Await()); } catch (Exception e) when (e.IsInterruptedException()) { @@ -344,7 +344,7 @@ namespace Lucene.Net.Index } if (Random.NextBoolean()) { - Thread.Sleep(0); + Thread.Yield(); } } } @@ -355,6 +355,7 @@ namespace Lucene.Net.Index exceptions.Add(e); } + // LUCENENET specific - possible InvalidOperationException here if Signal() is called more than what is required to decrement to zero if (!sync.updateJoin.IsSet) { sync.updateJoin.Signal(); @@ -380,7 +381,9 @@ namespace Lucene.Net.Index { thread.Start(); } - Thread.Sleep(1); // let them start + + // LUCENENET: This was not in Lucene, but was once a part of this class. We may need to put this back if this test misbehaves in the future. + //Thread.Sleep(1); // let them start } public static void Join(ThreadJob[] toJoin) @@ -439,7 +442,7 @@ namespace Lucene.Net.Index } if (Random.NextBoolean()) { - Thread.Sleep(0); + Thread.Yield(); } else { @@ -466,9 +469,9 @@ namespace Lucene.Net.Index this.leftCheckpoint = new CountdownEvent(numUpdaters); } - public bool @await() + public bool Await() { - return waiter.Wait(new TimeSpan(0, 0, 0, 10)); + return waiter.Wait(TimeSpan.FromSeconds(10)); } } }
