Team Ai
Datasetpublic

MegaBites-AI/Windows-powershell

sourceHugging Facemitupdated 6mo agoView on Hugging Face
0likes372downloads
Start-Sleep.Tests.ps175 linesDownload Raw Back to Microsoft.PowerShell.Utility
1# Copyright (c) Microsoft Corporation.2# Licensed under the MIT License.3Describe "Start-Sleep DRT Unit Tests" -Tags "CI" {4 5    # WaitHandle.WaitOne(milliseconds, exitContext) is not accurate.6    # The actual wait time can vary from 1450ms to 1700ms.7    $minTime = 14508    $maxTime = 17009 10    It "Should work properly when sleeping with Second" {11        $watch = [System.Diagnostics.Stopwatch]::StartNew()12        Start-Sleep -Seconds 1.513        $watch.Stop()14        $watch.ElapsedMilliseconds | Should -BeGreaterThan $minTime15        $watch.ElapsedMilliseconds | Should -BeLessThan $maxTime16    }17 18    It "Should work properly when sleeping with Milliseconds" {19        $watch = [System.Diagnostics.Stopwatch]::StartNew()20        Start-Sleep -Milliseconds 150021        $watch.Stop()22        $watch.ElapsedMilliseconds | Should -BeGreaterThan $minTime23        $watch.ElapsedMilliseconds | Should -BeLessThan $maxTime24    }25 26    It "Should work properly when sleeping with a [TimeSpan]" {27        $duration = [timespan]::FromMilliseconds(1500)28        $watch = [System.Diagnostics.Stopwatch]::StartNew()29        Start-Sleep -Duration $duration30        $watch.Stop()31        $watch.ElapsedMilliseconds | Should -BeGreaterThan $minTime32        $watch.ElapsedMilliseconds | Should -BeLessThan $maxTime33    }34 35    It "Should work properly when sleeping with ms alias" {36        $watch = [System.Diagnostics.Stopwatch]::StartNew()37        Start-Sleep -ms 150038        $watch.Stop()39        $watch.ElapsedMilliseconds | Should -BeGreaterThan $minTime40        $watch.ElapsedMilliseconds | Should -BeLessThan $maxTime41    }42 43    It "Should work properly when sleeping without parameters" {44        $watch = [System.Diagnostics.Stopwatch]::StartNew()45        Start-Sleep 1.546        $watch.Stop()47        $watch.ElapsedMilliseconds | Should -BeGreaterThan $minTime48        $watch.ElapsedMilliseconds | Should -BeLessThan $maxTime49    }50 51    It "Should work properly when sleeping without parameters from [timespan]" {52        $duration = [timespan]::FromMilliseconds(1500)53        $watch = [System.Diagnostics.Stopwatch]::StartNew()54        Start-Sleep $duration55        $watch.Stop()56        $watch.ElapsedMilliseconds | Should -BeGreaterThan $minTime57        $watch.ElapsedMilliseconds | Should -BeLessThan $maxTime58    }59 60    It "Should validate [timespan] parameter values" {61        { Start-Sleep -Duration    '0:00:01' } | Should -Not -Throw62        { Start-Sleep -Duration   '-0:00:01' } | Should -Throw -ErrorId 'ParameterArgumentValidationError,Microsoft.PowerShell.Commands.StartSleepCommand'63        { Start-Sleep -Duration '30.0:00:00' } | Should -Throw -ErrorId 'MaximumDurationExceeded,Microsoft.PowerShell.Commands.StartSleepCommand'64    }65}66 67Describe "Start-Sleep" -Tags "CI" {68    Context "Validate Start-Sleep works properly" {69        It "Should only sleep for at least 1 second" {70            $result = Measure-Command { Start-Sleep -s 1 }71            $result.TotalSeconds | Should -BeGreaterThan 0.2572        }73    }74}75