Skip to content

Commit

Permalink
fix: Expand range for wait test on mac
Browse files Browse the repository at this point in the history
  • Loading branch information
tsuyoshicho committed Mar 16, 2024
1 parent 4517cb6 commit 396d666
Showing 1 changed file with 60 additions and 33 deletions.
93 changes: 60 additions & 33 deletions test/Async/Promise.vimspec
Original file line number Diff line number Diff line change
Expand Up @@ -794,28 +794,42 @@ Describe Async.Promise
Assert Equals(p._state, PENDING)
" Timer accuracy fixing need
Assert Equals(P.wait(p, { 'interval': 200 }), ['resolved', v:null])
let done = reltimefloat(reltime(s)) * 1000
" interval period | 1 | 2 | 3 | 4 | 5 | 6
" elapsed time |* 0 |* 200 |* 400 |* 600 |* 800 |* 1000
" detect time range | +------+
" complete timing |---------------o 500
" lower limit : 600, upper limit : 800
Assert Compare(done, '>=', 600)
Assert Compare(done, '<=', 800)
if has('mac')
" Because of unstable result time on mac, we will expand the judgment range for the time test
" It underflows and overflows.
Assert Compare(done, '>=', 400)
Assert Compare(done, '<=', 1000)
else
let done = reltimefloat(reltime(s)) * 1000
" interval period | 1 | 2 | 3 | 4 | 5 | 6
" elapsed time |* 0 |* 200 |* 400 |* 600 |* 800 |* 1000
" detect time range | +------+
" complete timing |---------------o 500
" lower limit : 600, upper limit : 800
Assert Compare(done, '>=', 600)
Assert Compare(done, '<=', 800)
endif

let p = Wait(700).then({ -> 'resolved' })
let s = reltime()
Assert Equals(p._state, PENDING)
" Timer accuracy fixing need
Assert Equals(P.wait(p, { 'interval': 200 }), ['resolved', v:null])
let done = reltimefloat(reltime(s)) * 1000
" interval period | 1 | 2 | 3 | 4 | 5 | 6
" elapsed time |* 0 |* 200 |* 400 |* 600 |* 800 |* 1000
" detect time range | +------+
" complete timing |----------------------o 700
" lower limit : 800, upper limit : 1000
Assert Compare(done, '>=', 800)
Assert Compare(done, '<=', 1000)
if has('mac')
" Because of unstable result time on mac, we will expand the judgment range for the time test
" It underflows and overflows.
Assert Compare(done, '>=', 600)
Assert Compare(done, '<=', 1200)
else
let done = reltimefloat(reltime(s)) * 1000
" interval period | 1 | 2 | 3 | 4 | 5 | 6
" elapsed time |* 0 |* 200 |* 400 |* 600 |* 800 |* 1000
" detect time range | +------+
" complete timing |----------------------o 700
" lower limit : 800, upper limit : 1000
Assert Compare(done, '>=', 800)
Assert Compare(done, '<=', 1000)
endif
End

It waits within interval range ((interval * n) <= epoch <= (interval * (n + 1))), rejected pattern
Expand All @@ -824,29 +838,42 @@ Describe Async.Promise
Assert Equals(p._state, PENDING)
" Timer accuracy fixing need
Assert Equals(P.wait(p, { 'interval': 200 }), [v:null, 'rejected'])
let done = reltimefloat(reltime(s)) * 1000
" interval period | 1 | 2 | 3 | 4 | 5 | 6
" elapsed time |* 0 |* 200 |* 400 |* 600 |* 800 |* 1000
" detect time range | +------+
" complete timing |---------------o 500
" lower limit : 600, upper limit : 800
Assert Compare(done, '>=', 600)
Assert Compare(done, '<=', 800)

if has('mac')
" Because of unstable result time on mac, we will expand the judgment range for the time test
" It underflows and overflows.
Assert Compare(done, '>=', 400)
Assert Compare(done, '<=', 1000)
else
let done = reltimefloat(reltime(s)) * 1000
" interval period | 1 | 2 | 3 | 4 | 5 | 6
" elapsed time |* 0 |* 200 |* 400 |* 600 |* 800 |* 1000
" detect time range | +------+
" complete timing |---------------o 500
" lower limit : 600, upper limit : 800
Assert Compare(done, '>=', 600)
Assert Compare(done, '<=', 800)
endif

let p = Wait(700).then({ -> P.reject('rejected') })
let s = reltime()
Assert Equals(p._state, PENDING)
" Timer accuracy fixing need
Assert Equals(P.wait(p, { 'interval': 200 }), [v:null, 'rejected'])
let done = reltimefloat(reltime(s)) * 1000
" interval period | 1 | 2 | 3 | 4 | 5 | 6
" elapsed time |* 0 |* 200 |* 400 |* 600 |* 800 |* 1000
" detect time range | +------+
" complete timing |----------------------o 700
" lower limit : 800, upper limit : 1000
Assert Compare(done, '>=', 800)
Assert Compare(done, '<=', 1000)
if has('mac')
" Because of unstable result time on mac, we will expand the judgment range for the time test
" It underflows and overflows.
Assert Compare(done, '>=', 600)
Assert Compare(done, '<=', 1200)
else
let done = reltimefloat(reltime(s)) * 1000
" interval period | 1 | 2 | 3 | 4 | 5 | 6
" elapsed time |* 0 |* 200 |* 400 |* 600 |* 800 |* 1000
" detect time range | +------+
" complete timing |----------------------o 700
" lower limit : 800, upper limit : 1000
Assert Compare(done, '>=', 800)
Assert Compare(done, '<=', 1000)
endif
End
End

Expand Down

0 comments on commit 396d666

Please sign in to comment.