diff --git a/future.ml b/future.ml index 1fab5436..ca8eddb7 100644 --- a/future.ml +++ b/future.ml @@ -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 *) diff --git a/tests/test_future.ml b/tests/test_future.ml index 0c7b5a93..ce7420b4 100644 --- a/tests/test_future.ml +++ b/tests/test_future.ml @@ -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; ]