Skip to content

Commit 14e33c2

Browse files
committed
Make clock tests less fragile for CI.
1 parent 644ac8c commit 14e33c2

File tree

1 file changed

+6
-23
lines changed

1 file changed

+6
-23
lines changed

test/suite0007.janet

+6-23
Original file line numberDiff line numberDiff line change
@@ -333,29 +333,12 @@
333333

334334
(assert (pos? (length (gensym))) "gensym not empty, regression #753")
335335

336+
(assert-no-error (os/clock :realtime) "realtime clock")
337+
(assert-no-error (os/clock :cputime) "cputime clock")
338+
(assert-no-error (os/clock :monotonic) "monotonic clock")
336339

337-
# os/clock. These tests might prove fragile under CI because they
338-
# rely on measured time. We'll see.
339-
340-
(defmacro measure-time [clocks & body]
341-
(def [t1 t2] [(gensym) (gensym)])
342-
~(do
343-
(def ,t1 (map |(os/clock $) ,clocks))
344-
,;body
345-
(def ,t2 (map |(os/clock $) ,clocks))
346-
(zipcoll ,clocks (map |(- ;$) (map tuple ,t2 ,t1))))
347-
)
348-
349-
# Spin for 0.1 seconds
350-
(def dt (measure-time [:realtime :monotonic :cputime]
351-
(def t1 (os/clock :monotonic))
352-
(while (< (- (os/clock :monotonic) t1) 0.1) true)))
353-
(assert (> (dt :monotonic) 0.10))
354-
(assert (> (dt :cputime) 0.05))
355-
356-
# Sleep for 0.1 seconds
357-
(def dt (measure-time [:realtime :monotonic :cputime] (os/sleep 0.1)))
358-
(assert (> (dt :monotonic) 0.10))
359-
(assert (< (dt :cputime) 0.05))
340+
(def before (os/clock :monotonic))
341+
(def after (os/clock :monotonic))
342+
(assert (>= after before) "monotonic clock is monotonic")
360343

361344
(end-suite)

0 commit comments

Comments
 (0)