Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to pause runner between atomics & invoke-commandfix #161

Merged
merged 4 commits into from
Oct 14, 2023
Merged
Show file tree
Hide file tree
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
8 changes: 6 additions & 2 deletions Private/Invoke-ExecuteCommand.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ function Invoke-ExecuteCommand ($finalCommand, $executor, $executionPlatform, $T
$execPrefix = "/c";
$execExe = "cmd.exe";
$execCommand = $finalCommand -replace "`n", " & "
}
$arguments = $execPrefix,"$execCommand"
}
else {
$finalCommand = $finalCommand -replace "[\\](?!;)", "`\$&"
$finalCommand = $finalCommand -replace "[`"]", "`\$&"
$execCommand = $finalCommand -replace "(?<!;)\n", "; "
$arguments = "$execPrefix `"$execCommand`""

}
$arguments = "$execPrefix `"$execCommand`""
}
elseif ($executor -eq "powershell") {
$execCommand = $finalCommand -replace "`"", "`\`"`""
Expand Down Expand Up @@ -46,6 +48,8 @@ function Invoke-ExecuteCommand ($finalCommand, $executor, $executionPlatform, $T
IsTimeOut = $false
}
}

# Write-Host -ForegroundColor Magenta "$execExe $arguments"
if ($session) {
$scriptParentPath = Split-Path $import -Parent
$fp = Join-Path $scriptParentPath "Invoke-Process.ps1"
Expand Down
7 changes: 2 additions & 5 deletions Private/Invoke-Process.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function Invoke-Process {
[string]$FileName = "PowerShell.exe",

[Parameter(Mandatory = $false, Position = 1)]
[string]$Arguments = "",
[string[]]$Arguments = "",

[Parameter(Mandatory = $false, Position = 3)]
[Int]$TimeoutSeconds = 120,
Expand Down Expand Up @@ -46,8 +46,6 @@ function Invoke-Process {
$process.Start() > $null
$process.BeginOutputReadLine()
$process.BeginErrorReadLine()
$StdIn = $process.StandardInput
$StdIn.Close()
# wait for complete
$Timeout = [System.TimeSpan]::FromSeconds(($TimeoutSeconds))
$isTimeout = $false
Expand Down Expand Up @@ -138,7 +136,7 @@ function Invoke-Process {
[string]$FileName,

[parameter(Mandatory = $false)]
[string]$Arguments,
[string[]]$Arguments,

[parameter(Mandatory = $false)]
[string]$WorkingDirectory
Expand All @@ -150,7 +148,6 @@ function Invoke-Process {
$psi.UseShellExecute = $false
$psi.RedirectStandardOutput = $true
$psi.RedirectStandardError = $true
$psi.RedirectStandardInput = $true
$psi.FileName = $FileName
$psi.Arguments+= $Arguments
$psi.WorkingDirectory = $WorkingDirectory
Expand Down
22 changes: 20 additions & 2 deletions Public/Invoke-AtomicRunner.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ function Invoke-AtomicRunner {
[Parameter(Mandatory = $false)]
$ListOfAtomics,

[parameter(Mandatory = $false)]
[ValidateRange(0, [int]::MaxValue)]
[int] $PauseBetweenAtomics,

[Parameter(Mandatory = $false, ValueFromRemainingArguments = $true)]
$OtherArgs
)
Expand Down Expand Up @@ -70,6 +74,14 @@ function Invoke-AtomicRunner {
}
if ($Cleanup) { if (Get-Command 'Invoke-AtomicRunnerPostAtomicCleanupHook' -errorAction SilentlyContinue) { Invoke-AtomicRunnerPostAtomicCleanupHook } }
elseif (-not($ShowDetails -or $CheckPrereqs -or $ShowDetailsBrief -or $GetPrereqs)) { if (Get-Command 'Invoke-AtomicRunnerPostAtomicHook' -errorAction SilentlyContinue) { Invoke-AtomicRunnerPostAtomicHook } }
if ($timeToPause -gt 0) {
Write-Host "Sleeping for $timeToPause seconds..."
Start-Sleep $timeToPause
}
elseif ($timeToPause -eq 0) {
Write-Host 'Press any key to continue...';
$null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown');
}
}

function Rename-ThisComputer ($tr, $basehostname) {
Expand Down Expand Up @@ -158,11 +170,17 @@ function Invoke-AtomicRunner {
}
}
}

if ($PSBoundParameters.ContainsKey("PauseBetweenAtomics")) {
$timeToPause = $PauseBetweenAtomics
}
else {
$timeToPause = $null
}
$htvars += [Hashtable]$PSBoundParameters
$htvars.Remove('listOfAtomics') | Out-Null
$htvars.Remove('OtherArgs') | Out-Null
$htvars.Remove('Cleanup') | Out-Null
$htvars.Remove('PauseBetweenAtomics') | Out-Null

$schedule = Get-Schedule $listOfAtomics
# If the schedule is empty, end process
Expand Down Expand Up @@ -232,4 +250,4 @@ function Invoke-AtomicRunner {
Rename-ThisComputer $tr $artConfig.basehostname

}
}
}
12 changes: 6 additions & 6 deletions Public/Invoke-AtomicTest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ function Invoke-AtomicTest {
$ShortTestNumbers = $AtomicTechniqueParams[-1]
}

if ($TestNumbers -eq $null -and $ShortTestNumbers -ne $null) {
if ($null -eq $TestNumbers -and $null -ne $ShortTestNumbers) {
$TestNumbers = $ShortTestNumbers -split ','
}

Expand All @@ -222,15 +222,15 @@ function Invoke-AtomicTest {
$commandLine = "$commandLine -ShowDetailsBrief $ShowDetailsBrief"
}

if ($TestNumbers -ne $null) {
if ($null -ne $TestNumbers) {
$commandLine = "$commandLine -TestNumbers $TestNumbers"
}

if ($TestNames -ne $null) {
if ($null -ne $TestNames) {
$commandLine = "$commandLine -TestNames $TestNames"
}

if ($TestGuids -ne $null) {
if ($null -ne $TestGuids) {
$commandLine = "$commandLine -TestGuids $TestGuids"
}

Expand Down Expand Up @@ -285,7 +285,7 @@ function Invoke-AtomicTest {
$commandLine = "$commandLine -KeepStdOutStdErrFiles $KeepStdOutStdErrFiles"
}

if ($LoggingModule -ne $null) {
if ($null -ne $LoggingModule) {
$commandLine = "$commandLine -LoggingModule $LoggingModule"
}

Expand Down Expand Up @@ -368,7 +368,7 @@ function Invoke-AtomicTest {

$testCount++

if (($ShowDetails -or $ShowDetailsBrief) -and -not $anyOS) {
if (-not $anyOS) {
if ( -not $(Platform-IncludesCloud) -and -Not $test.supported_platforms.Contains($executionPlatform) ) {
Write-Verbose -Message "Unable to run non-$executionPlatform tests"
continue
Expand Down