Skip to content

Commit

Permalink
Merge pull request proxb#138 from MVKozlov/master
Browse files Browse the repository at this point in the history
Multiple fixes for PSv2, Memory
  • Loading branch information
proxb authored Apr 9, 2017
2 parents 59c0293 + d17fa94 commit b878ff8
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 14 deletions.
24 changes: 14 additions & 10 deletions PoshRSJob/PoshRSJob.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ $PoshRS_jobCleanup.PowerShell = [PowerShell]::Create().AddScript({
Foreach($job in $PoshRS_Jobs) {
If ($job.Handle.isCompleted -AND (-NOT $Job.Completed)) {
#$PoshRS_jobCleanup.Host.UI.WriteVerboseLine("$($Job.Id) completed")
$Data = $null
Try {
$Data = $job.InnerJob.EndInvoke($job.Handle)
} Catch {
Expand All @@ -153,13 +154,13 @@ $PoshRS_jobCleanup.PowerShell = [PowerShell]::Create().AddScript({
}
#$PoshRS_jobCleanup.Host.UI.WriteVerboseLine("$($Job.Id) Disposing job")
$job.InnerJob.dispose()
$job.Completed = $True
#Return type from Invoke() is a generic collection; need to verify the first index is not NULL
If (($Data.Count -gt 0) -AND (-NOT ($Data.Count -eq 1 -AND $Null -eq $Data[0]))) {
$job.output = $Data
$job.HasMoreData = $True
}
$Error.Clear()
$job.Completed = $True
}
}
[System.Threading.Monitor]::Exit($PoshRS_Jobs.syncroot)
Expand Down Expand Up @@ -192,24 +193,23 @@ $PoshRS_RunspacePoolCleanup.PowerShell = [PowerShell]::Create().AddScript({
#Routine to handle completed runspaces
Do {
#$ParentHost.ui.WriteVerboseLine("Beginning Do Statement")
If ($DisposePoshRS_RunspacePools) {
#Perform garbage collection
[gc]::Collect()
}
$DisposePoshRS_RunspacePools=$False
If ($PoshRS_RunspacePools.Count -gt 0) {
#$ParentHost.ui.WriteVerboseLine("$($PoshRS_RunspacePools | Out-String)")
[System.Threading.Monitor]::Enter($PoshRS_RunspacePools.syncroot)
Foreach($RunspacePool in $PoshRS_RunspacePools) {
#$ParentHost.ui.WriteVerboseLine("RunspacePool <$($RunspacePool.RunspaceID)> | MaxJobs: $($RunspacePool.MaxJobs) | AvailJobs: $($RunspacePool.AvailableJobs)")
#$ParentHost.ui.WriteVerboseLine("RunspacePool <$($RunspacePool.RunspacePoolID)> | MaxJobs: $($RunspacePool.MaxJobs) | AvailJobs: $($RunspacePool.AvailableJobs)")
If (($RunspacePool.AvailableJobs -eq $RunspacePool.MaxJobs) -AND $PoshRS_RunspacePools.LastActivity.Ticks -ne 0) {
If ((Get-Date).Ticks - $RunspacePool.LastActivity.Ticks -gt $PoshRS_RunspacePoolCleanup.Timeout) {
#Dispose of runspace pool
$RunspacePool.RunspacePool.Close()
$RunspacePool.RunspacePool.Dispose()
$RunspacePool.CanDispose = $True
$DisposePoshRS_RunspacePools=$True

#Perform garbage collection
[gc]::Collect()
Start-Sleep -Seconds 5
[gc]::Collect()
}
} Else {
$RunspacePool.LastActivity = (Get-Date)
Expand All @@ -221,15 +221,19 @@ $PoshRS_RunspacePoolCleanup.PowerShell = [PowerShell]::Create().AddScript({
$TempCollection | Where-Object {
$_.CanDispose
} | ForEach-Object {
#$ParentHost.ui.WriteVerboseLine("Removing runspacepool <$($_.RunspaceID)>")
#$ParentHost.ui.WriteVerboseLine("Removing runspacepool <$($_.RunspacePoolID)>")
[void]$PoshRS_RunspacePools.Remove($_)
}
#Not setting this to silentlycontinue seems to cause another runspace to be created if an error occurs
Remove-Variable TempCollection -ErrorAction SilentlyContinue
}
#Not setting this to silentlycontinue seems to cause another runspace to be created if an error occurs
Remove-Variable TempCollection -ErrorAction SilentlyContinue
[System.Threading.Monitor]::Exit($PoshRS_RunspacePools.syncroot)
}
#$ParentHost.ui.WriteVerboseLine("Sleeping")
If ($DisposePoshRS_RunspacePools) {
#Perform garbage collection
[gc]::Collect()
}
Start-Sleep -Milliseconds 5000
} while ($PoshRS_RunspacePoolCleanup.Flag)
})
Expand Down
3 changes: 3 additions & 0 deletions PoshRSJob/Private/ConvertScriptBlockV2.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@
[void]$StringBuilder.Append($Tokens[$i].Content)
}
}
'Type' {
[void]$StringBuilder.Append('[{0}]' -f $Tokens[$i].Content)
}
Default {
[void]$StringBuilder.Append($Tokens[$i].Content)
}
Expand Down
4 changes: 2 additions & 2 deletions Tests/PoshRSJob.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ Describe "Wait-RSJob PS$PSVersion" {
}
}

<#

Describe "Test RSJob Throttling" {
It "Full Pipe input" {
$StartDate = Get-Date
Expand All @@ -255,7 +255,7 @@ Describe "Test RSJob Throttling" {
( $EndDate - $StartDate ).TotalSeconds -gt 25 | Should be $True
}
}
#>


Describe "Module OnRemove Actions PS$PSVersion" {
Context 'Strict mode' {
Expand Down
11 changes: 10 additions & 1 deletion Tests/appveyor.pester.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,16 @@ param(
{
"`n`tSTATUS: Testing with PowerShell $PSVersion`n"

Import-Module Pester
if ($PSVersionTable.PSVersion.Major -gt 2) {
Import-Module Pester
Get-Module Pester | Select-Object -ExpandProperty Path | Set-Content -Path "$ProjectRoot\PesterPath.txt"
}
else {
$PesterPath = Get-Content -Path "$ProjectRoot\PesterPath.txt"
if ($PesterPath) {
Import-Module $PesterPath
}
}

Invoke-Pester @Verbose -Path "$ProjectRoot\Tests" -OutputFormat NUnitXml -OutputFile "$ProjectRoot\$TestFile" -PassThru |
Export-Clixml -Path "$ProjectRoot\PesterResults_PS$PSVersion`_$Timestamp.xml"
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ test_script:
# Test with native PS version
- ps: . .\Tests\appveyor.pester.ps1 -Test
# Test with PS version 2
# - ps: powershell.exe -version 2.0 -executionpolicy bypass -noprofile -file .\Tests\appveyor.pester.ps1 -Test
- ps: powershell.exe -version 2.0 -executionpolicy bypass -noprofile -file .\Tests\appveyor.pester.ps1 -Test
# Finalize pass - collect and upload results
- ps: . .\Tests\appveyor.pester.ps1 -Finalize

0 comments on commit b878ff8

Please sign in to comment.