mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 11:15:31 -05:00
test: use more deterministic test for timer
This commit is contained in:
parent
7cefde490b
commit
7bdf6f6cef
1 changed files with 5 additions and 2 deletions
|
|
@ -157,16 +157,19 @@ let every ?delay timer d ~f =
|
|||
let start = Unix.gettimeofday() in
|
||||
let timer = create() in
|
||||
let res = CCLock.create 0 in
|
||||
let sem = CCSemaphore.create 1 in
|
||||
CCSemaphore.acquire 1 sem;
|
||||
let stop = ref 0. in
|
||||
every timer 0.1
|
||||
~f:(fun () ->
|
||||
if CCLock.incr_then_get res > 5 then (
|
||||
stop := Unix.gettimeofday();
|
||||
CCSemaphore.release 1 sem;
|
||||
raise ExitEvery
|
||||
));
|
||||
Thread.delay 0.7;
|
||||
CCSemaphore.acquire 1 sem; (* wait *)
|
||||
OUnit.assert_equal ~printer:CCInt.to_string 6 (CCLock.get res);
|
||||
OUnit.assert_bool "estimate delay" (abs_float (!stop -. start -. 0.5) < 0.1);
|
||||
OUnit.assert_bool "estimate delay" (abs_float (!stop -. start -. 0.5) < 0.2);
|
||||
*)
|
||||
|
||||
let active timer = not timer.stop
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue