diff --git a/src/System.Linq.Expressions/tests/CompilerTests.cs b/src/System.Linq.Expressions/tests/CompilerTests.cs index 1b55caa765d8..54f574597bb3 100644 --- a/src/System.Linq.Expressions/tests/CompilerTests.cs +++ b/src/System.Linq.Expressions/tests/CompilerTests.cs @@ -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 @@ -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 f = Expression.Lambda>(e).Compile(useInterpreter); + Func 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>(e).Compile(useInterpreter), 1); + t.Start(); + t.Join(); Assert.Equal(n, f()); }