mirror of
https://github.com/janet-lang/janet
synced 2024-11-05 08:16:16 +00:00
Make clock tests less fragile for CI.
This commit is contained in:
parent
644ac8caf8
commit
14e33c295f
@ -333,29 +333,12 @@
|
||||
|
||||
(assert (pos? (length (gensym))) "gensym not empty, regression #753")
|
||||
|
||||
(assert-no-error (os/clock :realtime) "realtime clock")
|
||||
(assert-no-error (os/clock :cputime) "cputime clock")
|
||||
(assert-no-error (os/clock :monotonic) "monotonic clock")
|
||||
|
||||
# os/clock. These tests might prove fragile under CI because they
|
||||
# rely on measured time. We'll see.
|
||||
|
||||
(defmacro measure-time [clocks & body]
|
||||
(def [t1 t2] [(gensym) (gensym)])
|
||||
~(do
|
||||
(def ,t1 (map |(os/clock $) ,clocks))
|
||||
,;body
|
||||
(def ,t2 (map |(os/clock $) ,clocks))
|
||||
(zipcoll ,clocks (map |(- ;$) (map tuple ,t2 ,t1))))
|
||||
)
|
||||
|
||||
# Spin for 0.1 seconds
|
||||
(def dt (measure-time [:realtime :monotonic :cputime]
|
||||
(def t1 (os/clock :monotonic))
|
||||
(while (< (- (os/clock :monotonic) t1) 0.1) true)))
|
||||
(assert (> (dt :monotonic) 0.10))
|
||||
(assert (> (dt :cputime) 0.05))
|
||||
|
||||
# Sleep for 0.1 seconds
|
||||
(def dt (measure-time [:realtime :monotonic :cputime] (os/sleep 0.1)))
|
||||
(assert (> (dt :monotonic) 0.10))
|
||||
(assert (< (dt :cputime) 0.05))
|
||||
(def before (os/clock :monotonic))
|
||||
(def after (os/clock :monotonic))
|
||||
(assert (>= after before) "monotonic clock is monotonic")
|
||||
|
||||
(end-suite)
|
||||
|
Loading…
Reference in New Issue
Block a user