Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -196,19 +196,13 @@ Categories=Application;
elseif ($IsLinux) {
# Validate on Linux by reassociating default app for text file
& $TestFile
$startTime = Get-Date
# It may take time for handler to start
while (((Get-Date) - $startTime).TotalSeconds -lt 10 -and (-not (Test-Path "$HOME/nativeCommandProcessor.Success"))) {
Start-Sleep -Milliseconds 100
}
Wait-FileToBePresent -File "$HOME/nativeCommandProcessor.Success" -TimeoutInSeconds 10 -IntervalInMilliseconds 100
Get-Content $HOME/nativeCommandProcessor.Success | Should Be $TestFile
}
else {
& $TestFile
$startTime = Get-Date
while (((Get-Date) - $startTime).TotalSeconds -lt 10 -and (!(Test-Path $TestDrive\foo.txt))) {
Start-Sleep -Milliseconds 100
}
Wait-FileToBePresent -File $TestDrive\foo.txt -TimeoutInSeconds 10 -IntervalInMilliseconds 100
"$TestDrive\foo.txt" | Should Exist
Get-Content $TestDrive\foo.txt | Should BeExactly $TestFile
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,12 +233,7 @@ Describe "Basic FileSystem Provider Tests" -Tags "CI" {
"Test timeout waiting for $cmdLine" | Set-Content -Path $errFile

runas.exe /trustlevel:0x20000 "$powershell -nop -c try { $cmdline -ErrorAction Stop } catch { `$_.FullyQualifiedErrorId | Out-File $errFile }; New-Item -Type File -Path $doneFile"

$startTime = Get-Date
while (((Get-Date) - $startTime).TotalSeconds -lt 15 -and -not (Test-Path $doneFile))
{
Start-Sleep -Milliseconds 100
}
Wait-FileToBePresent -File $doneFile -TimeoutInSeconds 15 -IntervalInMilliseconds 100

$err = Get-Content $errFile
$err | Should Be $expectedError
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,9 @@ Describe "Start-Process tests requiring admin" -Tags "Feature","RequireAdminOnWi
$fooFile = Join-Path $TestDrive "FooTest.foo"
New-Item $fooFile -ItemType File -Force
Start-Process $fooFile
$startTime = Get-Date
while (((Get-Date) - $startTime).TotalSeconds -lt 10 -and (!(Test-Path $testdrive\foo.txt)))
{
Start-Sleep -Milliseconds 100
}

Wait-FileToBePresent -File "$testdrive\foo.txt" -TimeoutInSeconds 10 -IntervalInMilliseconds 100

"$testdrive\foo.txt" | Should Exist
Get-Content $testdrive\foo.txt | Should BeExactly $fooFile
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,8 @@ Categories=Application;

$before = $windows.Count
Invoke-Item -Path $PSHOME
$startTime = Get-Date
# may take time for explorer to open window
while (((Get-Date) - $startTime).TotalSeconds -lt 10 -and ($windows.Count -eq $before))
{
Start-Sleep -Milliseconds 100
}
Wait-UntilTrue -sb { $windows.Count -gt $before } -TimeoutInMilliseconds (10*1000) -IntervalInMilliseconds 100 > $null
$after = $windows.Count

$before + 1 | Should Be $after
Expand All @@ -143,12 +139,8 @@ Categories=Application;
{
# validate on Unix by reassociating default app for directories
Invoke-Item -Path $PSHOME
$startTime = Get-Date
# may take time for handler to start
while (((Get-Date) - $startTime).TotalSeconds -lt 10 -and (-not (Test-Path "$HOME/InvokeItemTest.Success")))
{
Start-Sleep -Milliseconds 100
}
Wait-FileToBePresent -File "$HOME/InvokeItemTest.Success" -TimeoutInSeconds 10 -IntervalInMilliseconds 100
Get-Content $HOME/InvokeItemTest.Success | Should Be $PSHOME
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,7 @@ Describe "CredSSP cmdlet tests" -Tags 'Feature','RequireAdminOnWindows' {
param ($cmdline, $cmd)

runas.exe /trustlevel:0x20000 "$powershell -nop -c try { $cmdline } catch { `$_.FullyQualifiedErrorId | Out-File $errtxt }; New-Item -Type File -Path $donefile"
$startTime = Get-Date
while (((Get-Date) - $startTime).TotalSeconds -lt 5 -and -not (Test-Path "$donefile"))
{
Start-Sleep -Milliseconds 100
}
Wait-FileToBePresent -File $donefile -TimeoutInSeconds 5 -IntervalInMilliseconds 100
$errtxt | Should Exist
$err = Get-Content $errtxt
$err | Should Be "System.InvalidOperationException,Microsoft.WSMan.Management.$cmd"
Expand Down
2 changes: 1 addition & 1 deletion test/tools/Modules/HelpersCommon/HelpersCommon.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ Copyright = 'Copyright (C) Microsoft Corporation, All rights reserved.'

Description = 'Temporary module contains functions for using in tests'

FunctionsToExport = 'Wait-UntilTrue', 'Test-IsElevated', 'ShouldBeErrorId'
FunctionsToExport = 'Wait-UntilTrue', 'Test-IsElevated', 'ShouldBeErrorId', 'Wait-FileToBePresent'

}
22 changes: 16 additions & 6 deletions test/tools/Modules/HelpersCommon/HelpersCommon.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,28 @@ function Wait-UntilTrue

# Loop until the script block evaluates to true
while (-not ($sb.Invoke())) {
# Sleep for the specified interval
start-sleep -mil $intervalInMilliseconds

# If the timeout period has passed, throw an exception
if (([DateTime]::Now - $startTime).TotalMilliseconds -gt $timeoutInMilliseconds)
{
# If the timeout period has passed, return false
if (([DateTime]::Now - $startTime).TotalMilliseconds -gt $timeoutInMilliseconds) {
return $false
}
# Sleep for the specified interval
Start-Sleep -Milliseconds $intervalInMilliseconds
}
return $true
}

function Wait-FileToBePresent
{
[CmdletBinding()]
param (
[string]$File,
[int]$TimeoutInSeconds = 10,
[int]$IntervalInMilliseconds = 100
)

Wait-UntilTrue -sb { Test-Path $File } -TimeoutInMilliseconds ($TimeoutInSeconds*1000) -IntervalInMilliseconds $IntervalInMilliseconds > $null
}

function Test-IsElevated
{
$IsElevated = $False
Expand Down