You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by ni...@apache.org on 2020/08/24 18:29:59 UTC
[lucenenet] 12/13: Lucene.Net.Tests: Don't run tests that require
asserts unless asserts are enabled. (closes #326, see #313)
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 4b31e7cdf3a084a229980d53ac30e8ff89743a60
Author: Shad Storhaug <sh...@shadstorhaug.com>
AuthorDate: Sat Aug 22 15:26:32 2020 +0700
Lucene.Net.Tests: Don't run tests that require asserts unless asserts are enabled. (closes #326, see #313)
---
.../Index/TestFlushByRamOrCountsPolicy.cs | 15 +++++++++++++
.../Index/TestIndexWriterExceptions.cs | 26 +++++++++++++---------
2 files changed, 30 insertions(+), 11 deletions(-)
diff --git a/src/Lucene.Net.Tests/Index/TestFlushByRamOrCountsPolicy.cs b/src/Lucene.Net.Tests/Index/TestFlushByRamOrCountsPolicy.cs
index 4bdfe89..58bd570 100644
--- a/src/Lucene.Net.Tests/Index/TestFlushByRamOrCountsPolicy.cs
+++ b/src/Lucene.Net.Tests/Index/TestFlushByRamOrCountsPolicy.cs
@@ -1,5 +1,6 @@
using J2N.Threading;
using J2N.Threading.Atomic;
+using Lucene.Net.Diagnostics;
using Lucene.Net.Index.Extensions;
using Lucene.Net.Store;
using NUnit.Framework;
@@ -62,6 +63,9 @@ namespace Lucene.Net.Index
[Test]
public virtual void TestFlushByRam()
{
+ // LUCENENET specific - disable the test if asserts are not enabled
+ AssumeTrue("This test requires asserts to be enabled.", Debugging.AssertsEnabled);
+
double ramBuffer = (TestNightly ? 1 : 10) + AtLeast(2) + Random.NextDouble();
RunFlushByRam(1 + Random.Next(TestNightly ? 5 : 1), ramBuffer, false);
}
@@ -69,6 +73,9 @@ namespace Lucene.Net.Index
[Test]
public virtual void TestFlushByRamLargeBuffer()
{
+ // LUCENENET specific - disable the test if asserts are not enabled
+ AssumeTrue("This test requires asserts to be enabled.", Debugging.AssertsEnabled);
+
// with a 256 mb ram buffer we should never stall
RunFlushByRam(1 + Random.Next(TestNightly ? 5 : 1), 256d, true);
}
@@ -132,6 +139,9 @@ namespace Lucene.Net.Index
[Test]
public virtual void TestFlushDocCount()
{
+ // LUCENENET specific - disable the test if asserts are not enabled
+ AssumeTrue("This test requires asserts to be enabled.", Debugging.AssertsEnabled);
+
int[] numThreads = new int[] { 2 + AtLeast(1), 1 };
for (int i = 0; i < numThreads.Length; i++)
{
@@ -184,6 +194,9 @@ namespace Lucene.Net.Index
[Test]
public virtual void TestRandom()
{
+ // LUCENENET specific - disable the test if asserts are not enabled
+ AssumeTrue("This test requires asserts to be enabled.", Debugging.AssertsEnabled);
+
int numThreads = 1 + Random.Next(8);
int numDocumentsToIndex = 50 + AtLeast(70);
AtomicInt32 numDocs = new AtomicInt32(numDocumentsToIndex);
@@ -247,6 +260,8 @@ namespace Lucene.Net.Index
[Slow] // LUCENENET: occasionally
public virtual void TestStallControl()
{
+ // LUCENENET specific - disable the test if asserts are not enabled
+ AssumeTrue("This test requires asserts to be enabled.", Debugging.AssertsEnabled);
int[] numThreads = new int[] { 4 + Random.Next(8), 1 };
int numDocumentsToIndex = 50 + Random.Next(50);
diff --git a/src/Lucene.Net.Tests/Index/TestIndexWriterExceptions.cs b/src/Lucene.Net.Tests/Index/TestIndexWriterExceptions.cs
index e81a33d..58ce2a2 100644
--- a/src/Lucene.Net.Tests/Index/TestIndexWriterExceptions.cs
+++ b/src/Lucene.Net.Tests/Index/TestIndexWriterExceptions.cs
@@ -2,6 +2,7 @@ using J2N.Threading;
using J2N.Threading.Atomic;
using Lucene.Net.Analysis;
using Lucene.Net.Attributes;
+using Lucene.Net.Diagnostics;
using Lucene.Net.Documents;
using Lucene.Net.Index.Extensions;
using Lucene.Net.Store;
@@ -497,6 +498,9 @@ namespace Lucene.Net.Index
[Test]
public virtual void TestExceptionDocumentsWriterInit()
{
+ // LUCENENET specific - disable the test if asserts are not enabled
+ AssumeTrue("This test requires asserts to be enabled.", Debugging.AssertsEnabled);
+
Directory dir = NewDirectory();
TestPoint2 testPoint = new TestPoint2();
IndexWriter w = RandomIndexWriter.MockIndexWriter(dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random)), testPoint);
@@ -576,6 +580,9 @@ namespace Lucene.Net.Index
[Test]
public virtual void TestExceptionOnMergeInit([ValueSource(typeof(ConcurrentMergeSchedulerFactories), "Values")]Func<IConcurrentMergeScheduler> newScheduler)
{
+ // LUCENENET specific - disable the test if asserts are not enabled
+ AssumeTrue("This test requires asserts to be enabled.", Debugging.AssertsEnabled);
+
Directory dir = NewDirectory();
IndexWriterConfig conf = NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random)).SetMaxBufferedDocs(2).SetMergePolicy(NewLogMergePolicy());
@@ -1296,23 +1303,17 @@ namespace Lucene.Net.Index
[Test]
public virtual void TestRollbackExceptionHang()
{
+ // LUCENENET specific - disable the test if asserts are not enabled
+ AssumeTrue("This test requires asserts to be enabled.", Debugging.AssertsEnabled);
+
Directory dir = NewDirectory();
TestPoint4 testPoint = new TestPoint4();
IndexWriter w = RandomIndexWriter.MockIndexWriter(dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random)), testPoint);
AddDoc(w);
testPoint.doFail = true;
- try
- {
- w.Rollback();
- Assert.Fail("did not hit intentional RuntimeException");
- }
-#pragma warning disable 168
- catch (Exception re)
-#pragma warning restore 168
- {
- // expected
- }
+ // LUCENENET: Don't assert in try block
+ Assert.Throws<Exception>(() => w.Rollback(), "did not hit intentional RuntimeException");
testPoint.doFail = false;
w.Rollback();
@@ -2435,6 +2436,9 @@ namespace Lucene.Net.Index
[Test]
public virtual void TestExceptionDuringRollback()
{
+ // LUCENENET specific - disable the test if asserts are not enabled
+ AssumeTrue("This test requires asserts to be enabled.", Debugging.AssertsEnabled);
+
// currently: fail in two different places
string messageToFailOn = Random.NextBoolean() ? "rollback: done finish merges" : "rollback before checkpoint";