From e0ae7bf1366e9c155e04ee7193aa7d883fd27ad6 Mon Sep 17 00:00:00 2001 From: Paul Irwin Date: Wed, 1 Jan 2025 21:34:19 -0700 Subject: [PATCH 1/3] Finish [SuppressTempFileChecks] attribute functionality, #898 --- .../Util/LuceneTestCase.cs | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/Lucene.Net.TestFramework/Util/LuceneTestCase.cs b/src/Lucene.Net.TestFramework/Util/LuceneTestCase.cs index 51c64d50a2..3ab75d4984 100644 --- a/src/Lucene.Net.TestFramework/Util/LuceneTestCase.cs +++ b/src/Lucene.Net.TestFramework/Util/LuceneTestCase.cs @@ -440,7 +440,6 @@ public SuppressCodecsAttribute(params string[] value) public string[] Value { get; private set; } } - // LUCENENET TODO: Finish implementation /// /// Marks any suites which are known not to close all the temporary /// files. This may prevent temp files and folders from being cleaned @@ -3086,10 +3085,11 @@ private static void RegisterToRemoveAfterSuite(FileSystemInfo f) [MethodImpl(MethodImplOptions.NoInlining)] protected string GetFullMethodName([CallerMemberName] string memberName = "") { - return string.Format("{0}+{1}", this.GetType().Name, memberName); + return $"{this.GetType().Name}+{memberName}"; } - private static void CleanupTemporaryFiles() + // LUCENENET specific - this is equivalent to TemporaryFilesCleanupRule in Lucene + private void CleanupTemporaryFiles() { // Drain cleanup queue and clear it. FileSystemInfo[] everything; @@ -3126,19 +3126,20 @@ private static void CleanupTemporaryFiles() } catch (Exception e) when (e.IsIOException()) { - // Type suiteClass = RandomizedContext.Current.GetTargetType; - // if (suiteClass.IsAnnotationPresent(typeof(SuppressTempFileChecks))) - // { - Console.Error.WriteLine("WARNING: Leftover undeleted temporary files " + e.Message); - return; - // } + Type suiteClass = this.GetType(); + if (suiteClass.GetCustomAttribute(inherit: true) is { } suppressAttr) + { + Console.Error.WriteLine($"WARNING: Leftover undeleted temporary files (bugUrl: {suppressAttr.BugUrl}): {e.Message}"); + return; + } + throw; } } else { if (tempDirBasePath != null) { - Console.Error.WriteLine("NOTE: leaving temporary files on disk at: " + tempDirBasePath); + Console.Error.WriteLine($"NOTE: leaving temporary files on disk at: {tempDirBasePath}"); } } } From 5ca12ae4d07826c2956043029a91fe392f0bba63 Mon Sep 17 00:00:00 2001 From: Paul Irwin Date: Sat, 4 Jan 2025 17:09:58 -0700 Subject: [PATCH 2/3] PR feedback --- src/Lucene.Net.TestFramework/Util/LuceneTestCase.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Lucene.Net.TestFramework/Util/LuceneTestCase.cs b/src/Lucene.Net.TestFramework/Util/LuceneTestCase.cs index 3ab75d4984..1494a0d874 100644 --- a/src/Lucene.Net.TestFramework/Util/LuceneTestCase.cs +++ b/src/Lucene.Net.TestFramework/Util/LuceneTestCase.cs @@ -722,11 +722,11 @@ private static IList LoadCoreDirectories() /// internal static TestRuleSetupAndRestoreClassEnv ClassEnvRule { get; } = new TestRuleSetupAndRestoreClassEnv(); - // LUCENENET TODO + // LUCENENET TODO: Implement these rules /// /// Suite failure marker (any error in the test or suite scope). /// - public static readonly /*TestRuleMarkFailure*/ bool SuiteFailureMarker = true; // Means: was successful + public static /*TestRuleMarkFailure*/ bool SuiteFailureMarker = true; // Means: was successful ///// ///// Ignore tests after hitting a designated number of initial failures. This @@ -937,6 +937,10 @@ public virtual void TearDown() if (result.ResultState == ResultState.Failure || result.ResultState == ResultState.Error) { + // LUCENENET specific - Track that at least one test in the suite failed. + // LUCENENET TODO: finish implementation of RuleChains so this is not needed (#1088) + SuiteFailureMarker = false; + string message = $$""" {{result.Message}} @@ -3089,7 +3093,7 @@ protected string GetFullMethodName([CallerMemberName] string memberName = "") } // LUCENENET specific - this is equivalent to TemporaryFilesCleanupRule in Lucene - private void CleanupTemporaryFiles() + private static void CleanupTemporaryFiles() { // Drain cleanup queue and clear it. FileSystemInfo[] everything; @@ -3126,8 +3130,7 @@ private void CleanupTemporaryFiles() } catch (Exception e) when (e.IsIOException()) { - Type suiteClass = this.GetType(); - if (suiteClass.GetCustomAttribute(inherit: true) is { } suppressAttr) + if (RandomizedContext.CurrentContext.CurrentTest.TypeInfo?.Type.GetCustomAttribute(inherit: true) is { } suppressAttr) { Console.Error.WriteLine($"WARNING: Leftover undeleted temporary files (bugUrl: {suppressAttr.BugUrl}): {e.Message}"); return; From 50d5b45a805bb361ab57c291555c40891ec85405 Mon Sep 17 00:00:00 2001 From: Shad Storhaug Date: Thu, 9 Jan 2025 03:49:04 +0700 Subject: [PATCH 3/3] Lucene.Net.Util.LuceneTestCase: Removed setting SuiteFailureMarker to false, which will cause all additional tests keep temporary files on disk --- src/Lucene.Net.TestFramework/Util/LuceneTestCase.cs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Lucene.Net.TestFramework/Util/LuceneTestCase.cs b/src/Lucene.Net.TestFramework/Util/LuceneTestCase.cs index 1494a0d874..0aedb37e4a 100644 --- a/src/Lucene.Net.TestFramework/Util/LuceneTestCase.cs +++ b/src/Lucene.Net.TestFramework/Util/LuceneTestCase.cs @@ -937,10 +937,6 @@ public virtual void TearDown() if (result.ResultState == ResultState.Failure || result.ResultState == ResultState.Error) { - // LUCENENET specific - Track that at least one test in the suite failed. - // LUCENENET TODO: finish implementation of RuleChains so this is not needed (#1088) - SuiteFailureMarker = false; - string message = $$""" {{result.Message}}