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 @@ -43,8 +43,8 @@ public void Dispose()
/// </summary>
[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; }

/// <summary>
/// Allows sleep time to be specified in milliseconds.
Expand Down Expand Up @@ -97,7 +97,7 @@ protected override void ProcessRecord()
switch (ParameterSetName)
{
case "Seconds":
sleepTime = Seconds * 1000;
sleepTime = (int)(Seconds * 1000);
break;

case "Milliseconds":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,48 @@
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
}

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
}

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
}
}

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
}
}
}