Skip to content

Commit

Permalink
Fix intermittent failed TestMaxClauseLimitations tests, #1050 (#1054)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulirwin authored Dec 3, 2024
1 parent abe75de commit d1386d5
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/Lucene.Net.Tests/Search/TestMultiTermQueryRewrites.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using Lucene.Net.Documents;
using NUnit.Framework;
using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using Assert = Lucene.Net.TestFramework.Assert;
using Console = Lucene.Net.Util.SystemConsole;

Expand Down Expand Up @@ -243,36 +241,44 @@ public virtual void TestBoosts()
CheckBoosts(new MultiTermQuery.TopTermsScoringBooleanQueryRewrite(1024));
}

private void CheckMaxClauseLimitation(MultiTermQuery.RewriteMethod method, [CallerMemberName] string memberName = "")
// LUCENENET specific - made static
private static void CheckMaxClauseLimitation(MultiTermQuery.RewriteMethod method)
{
int savedMaxClauseCount = BooleanQuery.MaxClauseCount;
BooleanQuery.MaxClauseCount = 3;

MultiTermQuery mtq = TermRangeQuery.NewStringRange("data", "2", "7", true, true);
mtq.MultiTermRewriteMethod = (method);
mtq.MultiTermRewriteMethod = method;
try
{
multiSearcherDupls.Rewrite(mtq);
Assert.Fail("Should throw BooleanQuery.TooManyClauses");
}
catch (BooleanQuery.TooManyClausesException e)
catch (BooleanQuery.TooManyClausesException /*e*/)
{
// LUCENENET: The assertion below fails when Dynamic PGO is enabled (by default in .NET 8+) which can inline
// some methods at runtime. This causes the stack trace to be different than expected. Rather than forcing
// NoInlining on the method, we will just remove the assertion. It should only matter that the exception is
// thrown, not where it is thrown from.
// Original comment and assertion below:

// Maybe remove this assert in later versions, when internal API changes:
Assert.AreEqual("CheckMaxClauseCount", new StackTrace(e, false).GetFrames()[0].GetMethod().Name); //, "Should throw BooleanQuery.TooManyClauses with a stacktrace containing checkMaxClauseCount()");
// Assert.AreEqual("CheckMaxClauseCount", new StackTrace(e, false).GetFrames()[0].GetMethod()?.Name, "Should throw BooleanQuery.TooManyClauses with a stacktrace containing checkMaxClauseCount()");
}
finally
{
BooleanQuery.MaxClauseCount = savedMaxClauseCount;
}
}

private void CheckNoMaxClauseLimitation(MultiTermQuery.RewriteMethod method)
// LUCENENET specific - made static
private static void CheckNoMaxClauseLimitation(MultiTermQuery.RewriteMethod method)
{
int savedMaxClauseCount = BooleanQuery.MaxClauseCount;
BooleanQuery.MaxClauseCount = 3;

MultiTermQuery mtq = TermRangeQuery.NewStringRange("data", "2", "7", true, true);
mtq.MultiTermRewriteMethod = (method);
mtq.MultiTermRewriteMethod = method;
try
{
multiSearcherDupls.Rewrite(mtq);
Expand Down

0 comments on commit d1386d5

Please sign in to comment.