forked from apache/lucenenet
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added DisposeAfterSuite/DisposeAfterTest feature to test framework (a…
…pache#1096) * Lucene.Net.TestFramework: Implemented functionality of DisposeAfterTest() and DisposeAfterSuite() and removed TestMarkerFailure and SuiteMarkerFailure, since this info is already available through NUnit's TestExecutionContext. * Lucene.Net.Util.TestRuleMarkFailure: Eliminated the class and added comments to indicate why we don't need this class in .NET. It is not sensible to have it because result state is already tracked by NUnit and is context sensitive. * BUG: Lucene.Net.Tests.Grouping/TestGroupingExtra.cs: Directory, IndexWriter, and IndexReader were not being disposed in any of these tests. Not closing the wrapped reader was being detected by the test framework as a problem and casing it to fail the test run, so added using statements to each of these instances so they will be cleaned up at the end of each test. * Lucene.Net.Util.LuceneTestCase::OneTimeTearDown(): Log the class that caused any failure, so we can debug more easily. * Lucene.Net.Util.Fst.TestFSTs: Added SuppressTempFileChecks attribute to ignore the fact that the LineDocsFile is not being deleted. * Lucene.Net.Util.LifecycleScope: Marked internal - this is part of randomizedtesting and is not exposed publicly by Lucene. * Lucene.Net.Util.RandomizedContext: Changed to use Lazy<ConcurrentQueue<IDisposable>> to eliminate locking * Lucene.Net.Util.LifecycleScope: Added license header * Lucene.Net.Util: Added DisposableResourceInfo class to track scope, thread name, and caller stack trace so this info can be included in the output if there is an exception during dispose. * Lucene.Net.Util.DisposableResourceInfo: Added license header * Lucene.Net.Util.RandomizedContext: Reverted to using conextLock and regular List<T> to stay more closely aligned with the upstream randomizedtesting code. * Lucene.Net.Util.LuceneTestCase (TearDown() + OneTimeTearDown()): use empty throw statement to preserve stack details, since we are still in the finally block. * Lucene.Net.Util.RandomizedContext: Lazily-load random seed string only if it is required * Lucene.Net.Util.RandomizedContext: Updated comments
- Loading branch information
1 parent
84b7c60
commit dcfa0e2
Showing
10 changed files
with
532 additions
and
278 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
src/Lucene.Net.TestFramework/Support/Util/DisposableResourceInfo.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
#nullable enable | ||
|
||
namespace Lucene.Net.Util | ||
{ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/// <summary> | ||
/// Allocation information (Thread, allocation stack) for tracking disposable | ||
/// resources. | ||
/// </summary> | ||
internal sealed class DisposableResourceInfo // From randomizedtesing | ||
{ | ||
private readonly IDisposable resource; | ||
private readonly LifecycleScope scope; | ||
private readonly StackTrace stackTrace; | ||
private readonly string? threadName; | ||
|
||
public DisposableResourceInfo(IDisposable resource, LifecycleScope scope, string? threadName, StackTrace stackTrace) | ||
{ | ||
Debug.Assert(resource != null); | ||
|
||
this.resource = resource!; | ||
this.scope = scope; | ||
this.stackTrace = stackTrace; | ||
this.threadName = threadName; | ||
} | ||
|
||
public IDisposable Resource => resource; | ||
|
||
public StackTrace StackTrace => stackTrace; | ||
|
||
public LifecycleScope Scope => scope; | ||
|
||
public string? ThreadName => threadName; | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/Lucene.Net.TestFramework/Support/Util/LifecycleScope.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Lucene.Net.Util | ||
{ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/// <summary> | ||
/// Lifecycle stages for tracking resources. | ||
/// </summary> | ||
internal enum LifecycleScope // From randomizedtesing | ||
{ | ||
/// <summary> | ||
/// A single test case. | ||
/// </summary> | ||
TEST, | ||
|
||
/// <summary> | ||
/// A single suite (class). | ||
/// </summary> | ||
SUITE | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.