1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

tests: fix msvc transient failures when sleep_ms takes longer

This commit is contained in:
Delyan Angelov 2020-05-01 11:58:47 +03:00
parent 51da324465
commit 84785bbb59

View File

@ -1,5 +1,8 @@
import time import time
// NB: on CI jobs, especially msvc ones, sleep_ms may sleep for much more
// time than you have specified. To avoid false positives from CI test
// failures, some of the asserts will be run only if you pass `-d stopwatch`
fn test_stopwatch_works_as_intended() { fn test_stopwatch_works_as_intended() {
sw := time.new_stopwatch() sw := time.new_stopwatch()
// sample code that you want to measure: // sample code that you want to measure:
@ -19,10 +22,14 @@ fn test_stopwatch_time_between_pause_and_start_should_be_skipped_in_elapsed(){
time.sleep_ms(10) time.sleep_ms(10)
// eprintln('${sw.elapsed().milliseconds()}ms') // eprintln('${sw.elapsed().milliseconds()}ms')
assert sw.elapsed().milliseconds() >= 10 assert sw.elapsed().milliseconds() >= 10
$if stopwatch {
assert sw.elapsed().milliseconds() < 20 assert sw.elapsed().milliseconds() < 20
}
sw.start() sw.start()
time.sleep_ms(10) // B time.sleep_ms(10) // B
// Here, sw.elapsed() should be ~10ms (from A) + 10ms (from B) = 20ms // Here, sw.elapsed() should be ~10ms (from A) + ~10ms (from B) >= 20ms
assert sw.elapsed().milliseconds() >= 20 assert sw.elapsed().milliseconds() >= 20
$if stopwatch {
assert sw.elapsed().milliseconds() < 30 assert sw.elapsed().milliseconds() < 30
} }
}