mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 11:15:31 -05:00
added a test for Future.Timer
This commit is contained in:
parent
8be147c50b
commit
bc38851de6
2 changed files with 14 additions and 4 deletions
|
|
@ -619,11 +619,9 @@ module Timer = struct
|
|||
} (** A timer for events *)
|
||||
|
||||
let cmp_tasks (f1,_) (f2,_) =
|
||||
if f1 < f2 then -1
|
||||
else if f1 > f2 then 1
|
||||
else 0
|
||||
compare f1 f2
|
||||
|
||||
let standby_wait = 300. (* when no task is scheduled *)
|
||||
let standby_wait = 30. (* when no task is scheduled *)
|
||||
let epsilon = 0.0001 (* accepted time diff for actions *)
|
||||
|
||||
(** Wait for next event, run it, and loop *)
|
||||
|
|
|
|||
|
|
@ -31,9 +31,21 @@ let test_time () =
|
|||
OUnit.assert_bool "parallelism" (stop -. start < 0.75);
|
||||
()
|
||||
|
||||
let test_timer () =
|
||||
let timer = Future.Timer.create () in
|
||||
let mvar = Future.MVar.full 1 in
|
||||
Future.Timer.schedule_in timer 0.5
|
||||
(fun () -> ignore (Future.MVar.update mvar (fun x -> x + 2)));
|
||||
Future.Timer.schedule_in timer 0.2
|
||||
(fun () -> ignore (Future.MVar.update mvar (fun x -> x * 4)));
|
||||
Thread.delay 0.7;
|
||||
OUnit.assert_equal 6 (Future.MVar.peek mvar);
|
||||
()
|
||||
|
||||
let suite =
|
||||
"test_future" >:::
|
||||
[ "test_mvar" >:: test_mvar;
|
||||
"test_parallel" >:: test_parallel;
|
||||
"test_time" >:: test_time;
|
||||
"test_timer" >:: test_timer;
|
||||
]
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue