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 744a9227ac9c348d4bbbfa9aa9b227faa0b58582 Author: Shad Storhaug <[email protected]> AuthorDate: Fri Sep 25 16:13:29 2020 +0700 Lucene.Net.Tests: Added logging in TestDuringAddIndexes() and TestTermVectorCorruption() to assist with debugging occasional test failures on Linux/macOS --- .../Util/LuceneTestCase.cs | 50 ++++++++++++++++++++++ .../Index/TestIndexWriterReader.cs | 4 ++ .../Index/TestTermVectorsWriter.cs | 5 +++ src/Lucene.Net/Store/NativeFSLockFactory.cs | 4 +- 4 files changed, 61 insertions(+), 2 deletions(-) diff --git a/src/Lucene.Net.TestFramework/Util/LuceneTestCase.cs b/src/Lucene.Net.TestFramework/Util/LuceneTestCase.cs index d32b79a..46a69cd 100644 --- a/src/Lucene.Net.TestFramework/Util/LuceneTestCase.cs +++ b/src/Lucene.Net.TestFramework/Util/LuceneTestCase.cs @@ -3585,6 +3585,56 @@ namespace Lucene.Net.Util } } + internal static void LogNativeFSFactoryDebugInfo() + { + // LUCENENET specific - log the current locking strategy used and HResult values + // for assistance troubleshooting problems on Linux/macOS + SystemConsole.WriteLine($"Locking Strategy: {NativeFSLockFactory.LockingStrategy}"); + SystemConsole.WriteLine($"Share Violation HResult: {(NativeFSLockFactory.HRESULT_FILE_SHARE_VIOLATION.HasValue ? NativeFSLockFactory.HRESULT_FILE_SHARE_VIOLATION.ToString() : "null")}"); + SystemConsole.WriteLine($"Lock Violation HResult: {(NativeFSLockFactory.HRESULT_FILE_LOCK_VIOLATION.HasValue ? NativeFSLockFactory.HRESULT_FILE_LOCK_VIOLATION.ToString() : "null")}"); + + string fileName; + try + { + // This could throw, but we don't care about this HResult value. + fileName = Path.GetTempFileName(); + } + catch (Exception e) + { + SystemConsole.WriteLine($"Error while creating temp file: {e}"); + return; + } + + Stream lockStream; + try + { + lockStream = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None, 1, FileOptions.None); + } + catch (Exception e) + { + SystemConsole.WriteLine($"Error while opening initial share stream: {e}"); + SystemConsole.WriteLine($"******* HResult: {e.HResult}"); + return; + } + try + { + // Try to get an exclusive lock on the file - this should throw an IOException with the current platform's HResult value for FileShare violation + using (var stream = new FileStream(fileName, FileMode.Open, FileAccess.Write, FileShare.None, 1, FileOptions.None)) + { + } + } + catch (IOException io) when (io.HResult != 0) + { + SystemConsole.WriteLine($"Successfully retrieved sharing violation."); + SystemConsole.WriteLine($"******* HResult: {io.HResult}"); + SystemConsole.WriteLine($"Exception: {io}"); + } + finally + { + lockStream.Dispose(); + } + } + private double nextNextGaussian; // LUCENENET specific private bool haveNextNextGaussian = false; // LUCENENET specific diff --git a/src/Lucene.Net.Tests/Index/TestIndexWriterReader.cs b/src/Lucene.Net.Tests/Index/TestIndexWriterReader.cs index e8372f3..34faea0 100644 --- a/src/Lucene.Net.Tests/Index/TestIndexWriterReader.cs +++ b/src/Lucene.Net.Tests/Index/TestIndexWriterReader.cs @@ -867,6 +867,10 @@ namespace Lucene.Net.Index [Slow] public virtual void TestDuringAddIndexes() { + // LUCENENET specific - log the current locking strategy used and HResult values + // for assistance troubleshooting problems on Linux/macOS + LogNativeFSFactoryDebugInfo(); + Directory dir1 = GetAssertNoDeletesDirectory(NewDirectory()); IndexWriter writer = new IndexWriter( dir1, diff --git a/src/Lucene.Net.Tests/Index/TestTermVectorsWriter.cs b/src/Lucene.Net.Tests/Index/TestTermVectorsWriter.cs index 3e7f17a..ea9e81a 100644 --- a/src/Lucene.Net.Tests/Index/TestTermVectorsWriter.cs +++ b/src/Lucene.Net.Tests/Index/TestTermVectorsWriter.cs @@ -1,6 +1,7 @@ using Lucene.Net.Documents; using Lucene.Net.Index.Extensions; using NUnit.Framework; +using System; using System.IO; using Assert = Lucene.Net.TestFramework.Assert; @@ -407,6 +408,10 @@ namespace Lucene.Net.Index [Test] public virtual void TestTermVectorCorruption() { + // LUCENENET specific - log the current locking strategy used and HResult values + // for assistance troubleshooting problems on Linux/macOS + LogNativeFSFactoryDebugInfo(); + Directory dir = NewDirectory(); for (int iter = 0; iter < 2; iter++) { diff --git a/src/Lucene.Net/Store/NativeFSLockFactory.cs b/src/Lucene.Net/Store/NativeFSLockFactory.cs index 3be1875..e76ba23 100644 --- a/src/Lucene.Net/Store/NativeFSLockFactory.cs +++ b/src/Lucene.Net/Store/NativeFSLockFactory.cs @@ -58,7 +58,7 @@ namespace Lucene.Net.Store // to take advantage of .NET FileShare locking in the Windows and Linux environments. public class NativeFSLockFactory : FSLockFactory { - private enum FSLockingStrategy + internal enum FSLockingStrategy { FileStreamLockViolation, FileSharingViolation, @@ -66,7 +66,7 @@ namespace Lucene.Net.Store } // LUCENENET: This controls the locking strategy used for the current operating system and framework - private static FSLockingStrategy LockingStrategy + internal static FSLockingStrategy LockingStrategy { get {
