diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/StartSleepCommand.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/StartSleepCommand.cs index b99476917..43840141e 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/StartSleepCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/StartSleepCommand.cs @@ -43,8 +43,8 @@ namespace Microsoft.PowerShell.Commands /// [Parameter(Position = 0, Mandatory = true, ParameterSetName = "Seconds", ValueFromPipeline = true, ValueFromPipelineByPropertyName = true)] - [ValidateRangeAttribute(0, int.MaxValue / 1000)] - public int Seconds { get; set; } + [ValidateRangeAttribute(0.0, (double)(int.MaxValue / 1000))] + public double Seconds { get; set; } /// /// Allows sleep time to be specified in milliseconds. @@ -97,7 +97,7 @@ namespace Microsoft.PowerShell.Commands switch (ParameterSetName) { case "Seconds": - sleepTime = Seconds * 1000; + sleepTime = (int)(Seconds * 1000); break; case "Milliseconds": diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Start-Sleep.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Start-Sleep.Tests.ps1 index b0d398340..19a27e7c5 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Start-Sleep.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Start-Sleep.Tests.ps1 @@ -3,14 +3,13 @@ Describe "Start-Sleep DRT Unit Tests" -Tags "CI" { # WaitHandle.WaitOne(milliseconds, exitContext) is not accurate. - # The wait time varies from 980ms to 1150ms from observation, so - # the tests here are changed to be greater than 950ms. - $minTime = 950 - $maxTime = 1200 + # The actual wait time can vary from 1450ms to 1700ms. + $minTime = 1450 + $maxTime = 1700 It "Should work properly when sleeping with Second" { $watch = [System.Diagnostics.Stopwatch]::StartNew() - Start-Sleep -Seconds 1 + Start-Sleep -Seconds 1.5 $watch.Stop() $watch.ElapsedMilliseconds | Should -BeGreaterThan $minTime $watch.ElapsedMilliseconds | Should -BeLessThan $maxTime @@ -18,7 +17,7 @@ Describe "Start-Sleep DRT Unit Tests" -Tags "CI" { It "Should work properly when sleeping with Milliseconds" { $watch = [System.Diagnostics.Stopwatch]::StartNew() - Start-Sleep -Milliseconds 1000 + Start-Sleep -Milliseconds 1500 $watch.Stop() $watch.ElapsedMilliseconds | Should -BeGreaterThan $minTime $watch.ElapsedMilliseconds | Should -BeLessThan $maxTime @@ -26,7 +25,15 @@ Describe "Start-Sleep DRT Unit Tests" -Tags "CI" { It "Should work properly when sleeping with ms alias" { $watch = [System.Diagnostics.Stopwatch]::StartNew() - Start-Sleep -ms 1000 + Start-Sleep -ms 1500 + $watch.Stop() + $watch.ElapsedMilliseconds | Should -BeGreaterThan $minTime + $watch.ElapsedMilliseconds | Should -BeLessThan $maxTime + } + + It "Should work properly when sleeping without parameters" { + $watch = [System.Diagnostics.Stopwatch]::StartNew() + Start-Sleep 1.5 $watch.Stop() $watch.ElapsedMilliseconds | Should -BeGreaterThan $minTime $watch.ElapsedMilliseconds | Should -BeLessThan $maxTime @@ -34,11 +41,10 @@ Describe "Start-Sleep DRT Unit Tests" -Tags "CI" { } Describe "Start-Sleep" -Tags "CI" { - Context "Validate Start-Sleep works properly" { - It "Should only sleep for at least 1 second" { - $result = Measure-Command { Start-Sleep -s 1 } - $result.TotalSeconds | Should -BeGreaterThan 0.25 - } + It "Should only sleep for at least 1 second" { + $result = Measure-Command { Start-Sleep -s 1 } + $result.TotalSeconds | Should -BeGreaterThan 0.25 + } } }