Skip to content

Commit

Permalink
fix: Update test for Promise.wait timing check
Browse files Browse the repository at this point in the history
  • Loading branch information
tsuyoshicho committed Mar 16, 2024
1 parent 969a97c commit c04319d
Showing 1 changed file with 51 additions and 21 deletions.
72 changes: 51 additions & 21 deletions test/Async/Promise.vimspec
Original file line number Diff line number Diff line change
Expand Up @@ -788,36 +788,66 @@ Describe Async.Promise
Assert Compare(done, '<=', 2000)
End

It waits at least the interval milliseconds (interval < epoch)
let p = Wait(1000).then({ -> 'resolved' })
It waits within interval range ((interval * n) <= epoch <= (interval * (n + 1))), resolved pattern
let p = Wait(500).then({ -> 'resolved' })
let s = reltime()
Assert Equals(p._state, PENDING)
" Timer accuracy fixing need
Assert Equals(P.wait(p, { 'interval': 340 }), ['resolved', v:null])
Assert Equals(P.wait(p, { 'interval': 200 }), ['resolved', v:null])
let done = reltimefloat(reltime(s)) * 1000
Assert Compare(done, '>=', 1000)
if has('mac')
" TODO: I know this is a terrible IDEA, but this assert makes osx test fails.
" Let's disable until we figure out why and how.
else
Assert Compare(done, '<=', 1360)
endif

let p = Wait(1000).then({ -> P.reject('rejected') })
" 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)

let p = Wait(700).then({ -> 'resolved' })
let s = reltime()
Assert Equals(p._state, PENDING)
" Timer accuracy fixing need
Assert Equals(P.wait(p, { 'interval': 340 }), [v:null, 'rejected'])
Assert Equals(P.wait(p, { 'interval': 200 }), ['resolved', v:null])
let done = reltimefloat(reltime(s)) * 1000
Assert Compare(done, '>=', 1000)
if has('mac')
" TODO: I know this is a terrible IDEA, but this assert makes osx test fails.
" Let's disable until we figure out why and how.
else
Assert Compare(done, '<=', 1360)
endif
" 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)
End

It waits within interval range ((interval * n) <= epoch <= (interval * (n + 1))), rejected pattern
let p = Wait(500).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 500
" lower limit : 600, upper limit : 800
Assert Compare(done, '>=', 600)
Assert Compare(done, '<=', 800)


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)
End
End

Describe .chain()
It returns a promise which resolves to an empty List when an empty factories has specified
Expand Down

0 comments on commit c04319d

Please sign in to comment.