8000 Reduce time for stack overflow test by JamesWTruher · Pull Request #9302 · PowerShell/PowerShell · GitHub
[go: up one dir, main page]

Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 36 additions & 6 deletions test/powershell/Host/ConsoleHost.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -480,14 +480,44 @@ foo
}

Context "Exception handling" {
It "Should handle a CallDepthOverflow" {
# Infinite recursion
function recurse
{
recurse $args
BeforeAll {
# the default stack size in PowerShell is 10000000, set the stack
# to something much smaller which will produce the error much faster
# I saw a reduction from 65 seconds to 79 milliseconds.
$classDefinition = @'
using System;
using System.Management.Automation;
using System.Management.Automation.Runspaces;
using System.Threading;
namespace StackTest {
public class StackDepthTest {
public static PowerShell ps;
public static int size = 512 * 1024;
public static void CauseError() {
Thread t = new Thread(RunPS, size);
t.Start();
t.Join();
}
public static void RunPS() {
InitialSessionState iss = InitialSessionState.CreateDefault2();
iss.ThreadOptions = PSThreadOptions.UseCurrentThread;
ps = PowerShell.Create(iss);
ps.AddScript("function recurse { recurse }; recurse").Invoke();
}
public static void GetPSError() {
if ( ps.Streams.Error.Count > 0) {
throw ps.Streams.Error[0].Exception.InnerException;
}
}
}
}
'@
$TestType = Add-Type -PassThru -TypeDefinition $classDefinition
}

{ recurse "args" } | Should -Throw -ErrorId "CallDepthOverflow"
It "Should handle a CallDepthOverflow" {
$TestType::CauseError()
{ $TestType::GetPSError() } | Should -Throw -ErrorId "CallDepthOverflow"
}
}

Expand Down
0