Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Commit

Permalink
Reduce time taken to test StackGuard and move to innerloop.
Browse files Browse the repository at this point in the history
We have a test that verifies that Expression compilation is protected
against stack overflow in the case of compiling deep expression trees,
but forcing a case that would cause such a problem by necessity
requires a large tree that takes a long time to compiile, so the test
is outerloop only.

Forcing the compilation to happen on the smallest possible stack
reduces the size of tree that would risk a stack overflow, and so can
test the same functionality in less than a second.

Do this, and move the test to innerloop.
  • Loading branch information
JonHanna committed Dec 12, 2016
1 parent dc74e6c commit 583e550
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/System.Linq.Expressions/tests/CompilerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.

using System.Runtime.CompilerServices;
using System.Threading;
using Xunit;

namespace System.Linq.Expressions.Tests
Expand All @@ -11,17 +12,21 @@ public static class CompilerTests
{
[Theory]
[ClassData(typeof(CompilationTypes))]
[OuterLoop("Takes over a minute to complete")]
public static void CompileDeepTree_NoStackOverflow(bool useInterpreter)
{
var e = (Expression)Expression.Constant(0);
Expression e = Expression.Constant(0);

int n = 10000;
int n = 100;

for (var i = 0; i < n; i++)
for (int i = 0; i < n; i++)
e = Expression.Add(e, Expression.Constant(1));

Func<int> f = Expression.Lambda<Func<int>>(e).Compile(useInterpreter);
Func<int> f = null;
// Request a stack size of 1 to get the minimum size allowed.
// This reduces the size of tree needed to risk a stack overflow.
Thread t = new Thread(() => f = Expression.Lambda<Func<int>>(e).Compile(useInterpreter), 1);
t.Start();
t.Join();

Assert.Equal(n, f());
}
Expand Down

0 comments on commit 583e550

Please sign in to comment.