time: add some tolerance for windows's minimum 1ms sleep resolution

pull/8172/head
Delyan Angelov 2021-01-17 19:16:08 +02:00
parent 3ee78dc961
commit 2677fcdf0c
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
1 changed files with 3 additions and 3 deletions

View File

@ -18,18 +18,18 @@ fn test_stopwatch_time_between_pause_and_start_should_be_skipped_in_elapsed() {
mut sw := time.new_stopwatch({})
time.sleep_ms(10) // A
eprintln('Elapsed after 10ms nap: ${sw.elapsed().milliseconds()}ms')
assert sw.elapsed().milliseconds() >= 10
assert sw.elapsed().milliseconds() >= 8 // sometimes it sleeps for 9ms on windows..
sw.pause()
time.sleep_ms(10)
eprintln('Elapsed after pause and another 10ms nap: ${sw.elapsed().milliseconds()}ms')
assert sw.elapsed().milliseconds() >= 10
assert sw.elapsed().milliseconds() >= 8
$if stopwatch ? {
assert sw.elapsed().milliseconds() < 20
}
sw.start()
time.sleep_ms(10) // B
eprintln('Elapsed after resume and another 10ms nap: ${sw.elapsed().milliseconds()}ms')
assert sw.elapsed().milliseconds() >= 20
assert sw.elapsed().milliseconds() >= 18
$if stopwatch ? {
assert sw.elapsed().milliseconds() < 30
}