Skip to content

Commit

Permalink
Lucene.Net.Tests: Don't run tests that require asserts unless asserts…
Browse files Browse the repository at this point in the history
… are enabled. (closes #326, see #313)
  • Loading branch information
NightOwl888 committed Aug 24, 2020
1 parent 3ddf3df commit 4b31e7c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
15 changes: 15 additions & 0 deletions src/Lucene.Net.Tests/Index/TestFlushByRamOrCountsPolicy.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -62,13 +63,19 @@ public override void AfterClass()
[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);
}

[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);
}
Expand Down Expand Up @@ -132,6 +139,9 @@ protected internal virtual void RunFlushByRam(int numThreads, double maxRamMB, b
[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++)
{
Expand Down Expand Up @@ -184,6 +194,9 @@ public virtual void TestFlushDocCount()
[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);
Expand Down Expand Up @@ -247,6 +260,8 @@ public virtual void TestRandom()
[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);
Expand Down
26 changes: 15 additions & 11 deletions src/Lucene.Net.Tests/Index/TestIndexWriterExceptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
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;
Expand Down Expand Up @@ -497,6 +498,9 @@ public override void Reset()
[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);
Expand Down Expand Up @@ -576,6 +580,9 @@ public void Apply(string name)
[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());

Expand Down Expand Up @@ -1296,23 +1303,17 @@ public void Apply(string name)
[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();
Expand Down Expand Up @@ -2435,6 +2436,9 @@ protected override void HandleMergeException(Exception exc)
[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";

Expand Down

0 comments on commit 4b31e7c

Please sign in to comment.