From commits-return-6334-archive-asf-public=cust-asf.ponee.io@lucenenet.apache.org Thu Jul 11 15:42:59 2019 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [207.244.88.153]) by mx-eu-01.ponee.io (Postfix) with SMTP id DF388180680 for ; Thu, 11 Jul 2019 17:42:57 +0200 (CEST) Received: (qmail 62862 invoked by uid 500); 11 Jul 2019 15:42:57 -0000 Mailing-List: contact commits-help@lucenenet.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: lucene-net-dev@lucenenet.apache.org Delivered-To: mailing list commits@lucenenet.apache.org Received: (qmail 62466 invoked by uid 99); 11 Jul 2019 15:42:56 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 11 Jul 2019 15:42:56 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id DBEBA85E06; Thu, 11 Jul 2019 15:42:55 +0000 (UTC) Date: Thu, 11 Jul 2019 15:42:56 +0000 To: "commits@lucenenet.apache.org" Subject: [lucenenet] 01/12: Fixed TestThreadInterruptDeadlock and TestTwoThreadsInterruptDeadlock MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit From: nightowl888@apache.org In-Reply-To: <156285977576.32449.17287307736849120410@gitbox.apache.org> References: <156285977576.32449.17287307736849120410@gitbox.apache.org> X-Git-Host: gitbox.apache.org X-Git-Repo: lucenenet X-Git-Refname: refs/heads/master X-Git-Reftype: branch X-Git-Rev: 71d143037a5753edea612c56219288d716b677c2 X-Git-NotificationType: diff X-Git-Multimail-Version: 1.5.dev Auto-Submitted: auto-generated Message-Id: <20190711154255.DBEBA85E06@gitbox.apache.org> 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 71d143037a5753edea612c56219288d716b677c2 Author: Simon Svensson AuthorDate: Thu Jan 17 21:10:41 2019 +0100 Fixed TestThreadInterruptDeadlock and TestTwoThreadsInterruptDeadlock --- .../Store/MockDirectoryWrapper.cs | 4 ++++ src/Lucene.Net.Tests/Index/TestIndexWriter.cs | 10 +--------- src/Lucene.Net/Index/IndexWriter.cs | 5 ++--- src/Lucene.Net/Support/Threading/ThreadClass.cs | 19 +++++++++++++++++++ 4 files changed, 26 insertions(+), 12 deletions(-) diff --git a/src/Lucene.Net.TestFramework/Store/MockDirectoryWrapper.cs b/src/Lucene.Net.TestFramework/Store/MockDirectoryWrapper.cs index 1994084..c8063a6 100644 --- a/src/Lucene.Net.TestFramework/Store/MockDirectoryWrapper.cs +++ b/src/Lucene.Net.TestFramework/Store/MockDirectoryWrapper.cs @@ -580,7 +580,11 @@ namespace Lucene.Net.Store { if (RandomState.NextBoolean()) { +#if NETSTANDARD1_6 Thread.Sleep(0); +#else + Thread.Yield(); +#endif } } diff --git a/src/Lucene.Net.Tests/Index/TestIndexWriter.cs b/src/Lucene.Net.Tests/Index/TestIndexWriter.cs index 963dc7d..9340d5f 100644 --- a/src/Lucene.Net.Tests/Index/TestIndexWriter.cs +++ b/src/Lucene.Net.Tests/Index/TestIndexWriter.cs @@ -1350,7 +1350,7 @@ namespace Lucene.Net.Index Console.WriteLine("TEST: now rollback"); } // clear interrupt state: - //Thread.interrupted(); + ThreadClass.Interrupted(); if (w != null) { try @@ -1438,10 +1438,6 @@ namespace Lucene.Net.Index #endif #endif -#if NETCOREAPP2_0 - fail("LUCENENET TODO: Uncaught exceptions on background thread causing test runner crash"); -#endif - IndexerThreadInterrupt t = new IndexerThreadInterrupt(this); t.SetDaemon(true); t.Start(); @@ -1484,10 +1480,6 @@ namespace Lucene.Net.Index [Test] public virtual void TestTwoThreadsInterruptDeadlock() { -#if NETCOREAPP2_0 - fail("LUCENENET TODO: Uncaught exceptions on background thread causing test runner crash"); -#endif - IndexerThreadInterrupt t1 = new IndexerThreadInterrupt(this); t1.SetDaemon(true); t1.Start(); diff --git a/src/Lucene.Net/Index/IndexWriter.cs b/src/Lucene.Net/Index/IndexWriter.cs index 9811ee3..53496bd 100644 --- a/src/Lucene.Net/Index/IndexWriter.cs +++ b/src/Lucene.Net/Index/IndexWriter.cs @@ -1,4 +1,5 @@ using Lucene.Net.Support; +using Lucene.Net.Support.Threading; using System; using System.Collections.Concurrent; using System.Collections.Generic; @@ -1180,9 +1181,7 @@ namespace Lucene.Net.Index try { // clean up merge scheduler in all cases, although flushing may have failed: - //interrupted = Thread.Interrupted(); - //LUCENE TO-DO - interrupted = false; + interrupted = ThreadClass.Interrupted(); if (waitForMerges) { diff --git a/src/Lucene.Net/Support/Threading/ThreadClass.cs b/src/Lucene.Net/Support/Threading/ThreadClass.cs index cdb3cb2..f959a4a 100644 --- a/src/Lucene.Net/Support/Threading/ThreadClass.cs +++ b/src/Lucene.Net/Support/Threading/ThreadClass.cs @@ -300,6 +300,25 @@ namespace Lucene.Net.Support.Threading return This; } + /// + /// LUCENENET specific. + /// Java has Thread.interrupted() which returns, and clears, the interrupt + /// flag of the current thread. .NET has no such method, so we're calling + /// Thread.Sleep to provoke the exception which will also clear the flag. + /// + /// + internal static bool Interrupted() { +#if !NETSTANDARD1_6 + try { + Thread.Sleep(0); + } catch (ThreadInterruptedException) { + return true; + } +#endif + + return false; + } + public static bool operator ==(ThreadClass t1, object t2) { if (((object)t1) == null) return t2 == null;