Merge pull request #2450 from vors/native-pipe

Refactor 'NativeCommandProcessor' to provide streaming behavior for running native commands in a pipeline.
This commit is contained in:
Dongbo Wang
2016-11-15 18:00:02 -08:00
committed by GitHub
5 changed files with 688 additions and 762 deletions
+3
View File
@@ -3,6 +3,9 @@ Changelog
Unreleased
----------
- Improve pipeline for native commands.
Start native process in Prepare() instead of Complete().
`ping | grep` doesn't block anymore.
- Added -Top and -Bottom parameters to Sort-Object
v6.0.0-alpha.12 - 2016-11-03
File diff suppressed because it is too large Load Diff
+47 -9
View File
@@ -1,5 +1,52 @@
using namespace System.Diagnostics
# Minishell (Singleshell) is a powershell concept.
# Its primary use-case is when somebody executes a scriptblock in the new powershell process.
# The objects are automatically marshelled to the child process and
# back to the parent session, so users can avoid custom
# serialization to pass objects between two processes.
Describe 'minishell for native executables' -Tag 'CI' {
BeforeAll {
$powershell = Join-Path -Path $PsHome -ChildPath "powershell"
}
Context 'Streams from minishell' {
It 'gets a hashtable object from minishell' {
$output = & $powershell -noprofile { @{'a' = 'b'} }
($output | measure).Count | Should Be 1
($output.GetType().Name) | Should Be 'Hashtable'
$output['a'] | Should Be 'b'
}
It 'gets the error stream from minishell' {
$output = & $powershell -noprofile { Write-Error 'foo' } 2>&1
($output | measure).Count | Should Be 1
($output.GetType().Name) | Should Be 'ErrorRecord'
$output.FullyQualifiedErrorId | Should Be 'Microsoft.PowerShell.Commands.WriteErrorException'
}
It 'gets the information stream from minishell' {
$output = & $powershell -noprofile { Write-Information 'foo' } 6>&1
($output.GetType().Name) | Should Be 'InformationRecord'
$output | Should Be 'foo'
}
}
Context 'Streams to minishell' {
It "passes input into minishell" {
$a = 1,2,3
$val = $a | & $powershell -noprofile -command { $input }
$val.Count | Should Be 3
$val[0] | Should Be 1
$val[1] | Should Be 2
$val[2] | Should Be 3
}
}
}
Describe "ConsoleHost unit tests" -tags "Feature" {
BeforeAll {
@@ -53,15 +100,6 @@ Describe "ConsoleHost unit tests" -tags "Feature" {
}
}
It "Verify Simple Interop Scenario Child Single Shell" {
$a = 1,2,3
$val = $a | & $powershell -noprofile -command { $input }
$val.Count | Should Be 3
$val[0] | Should Be 1
$val[1] | Should Be 2
$val[2] | Should Be 3
}
It "Verify Validate Dollar Error Populated should throw exception" {
$origEA = $ErrorActionPreference
$ErrorActionPreference = "Stop"
@@ -1,3 +1,24 @@
Describe 'native commands lifecycle' -tags 'Feature' {
BeforeAll {
$powershell = Join-Path -Path $PsHome -ChildPath "powershell"
}
It "native | ps | native doesn't block" {
$first = $true
& $powershell -command '1..10 | % {Start-Sleep -mill 100; $_}' | %{$_} | & $powershell -command '$input' | % {
if ($first)
{
$first = $false
$firstTime = [datetime]::Now
}
$lastTime = [datetime]::Now
}
$lastTime - $firstTime | Should BeGreaterThan ([timespan]::new(0, 0, 0, 0, 100)) # 100 milliseconds
}
}
Describe "Native Command Processor" -tags "Feature" {
BeforeAll {
@@ -51,3 +51,20 @@ Describe "Native streams behavior with PowerShell" -Tags 'CI' {
}
}
}
Describe 'piping powershell objects to finished native executable' -Tags 'CI' {
# Find where test/powershell is so we can find the echoargs command relative to it
$powershellTestDir = $PSScriptRoot
while ($powershellTestDir -notmatch 'test[\\/]powershell$') {
$powershellTestDir = Split-Path $powershellTestDir
}
$echoArgs = Join-Path (Split-Path $powershellTestDir) tools/EchoArgs/bin/echoargs
It 'doesn''t throw any exceptions, when we are piping to the closed executable' {
1..3 | % {
Start-Sleep -Milliseconds 100
# yeild some multi-line formatted object
@{'a' = 'b'}
} | & $echoArgs | Should Be $null
}
}