Fix foreach parallel when current drive is not available (#12197)

This commit is contained in:
Paul Higinbotham
2020-03-31 20:33:06 +05:00
committed by GitHub
parent c0c17ded03
commit a4c996d425
2 changed files with 18 additions and 0 deletions
@@ -449,6 +449,10 @@ namespace System.Management.Automation.PSTasks
Runspace.DefaultRunspace = runspace;
runspace.ExecutionContext.SessionState.Internal.SetLocation(_currentLocationPath);
}
catch (DriveNotFoundException)
{
// Allow task to run if current drive is not available.
}
finally
{
Runspace.DefaultRunspace = oldDefaultRunspace;
@@ -104,6 +104,20 @@ Describe 'ForEach-Object -Parallel Basic Tests' -Tags 'CI' {
$parallelScriptLocation = 1..1 | ForEach-Object -Parallel { $PWD }
$parallelScriptLocation.Path | Should -BeExactly $PWD.Path
}
It 'Verifies no terminating error if current working drive is not found' {
$oldLocation = Get-Location
try
{
New-PSDrive -Name ZZ -PSProvider FileSystem -Root $TestDrive
Set-Location -Path 'ZZ:'
{ 1..1 | ForEach-Object -Parallel { $_ } } | Should -Not -Throw
}
finally
{
Set-Location -Path $oldLocation
}
}
}
Describe 'ForEach-Object -Parallel common parameters' -Tags 'CI' {