diff --git a/bench/irmin-pack/dune b/bench/irmin-pack/dune index ae902eaf69..b95a7cc624 100644 --- a/bench/irmin-pack/dune +++ b/bench/irmin-pack/dune @@ -15,6 +15,7 @@ repr ppx_repr bench_common + mtime rusage)) (library diff --git a/bench/irmin-pack/trace_collection.ml b/bench/irmin-pack/trace_collection.ml index 5bc65110e4..20b7b03209 100644 --- a/bench/irmin-pack/trace_collection.ml +++ b/bench/irmin-pack/trace_collection.ml @@ -152,10 +152,7 @@ module Make_stat (Store : Irmin.Generic_key.KV) = struct } let now () = - Mtime_clock.now () - |> Mtime.to_uint64_ns - |> Int64.to_float - |> ( *. ) Mtime.ns_to_s + Mtime_clock.now () |> Mtime.to_uint64_ns |> Int64.to_float |> ( *. ) 1e-9 let create store_path prev_merge_durations = Def. diff --git a/irmin-test.opam b/irmin-test.opam index ba7eeed54b..bf35ef36c2 100644 --- a/irmin-test.opam +++ b/irmin-test.opam @@ -17,7 +17,7 @@ depends: [ "ppx_irmin" {= version} "ocaml" {>= "4.02.3"} "dune" {>= "2.9.0"} - "alcotest" {>= "1.5.0"} + "alcotest-lwt" {>= "1.5.0"} "mtime" {>= "1.0.0"} "astring" "fmt" @@ -30,7 +30,6 @@ depends: [ "metrics" {>= "0.2.0"} "hex" {with-test & >= "1.4.0"} "vector" {with-test & >= "1.0.0"} - "alcotest-lwt" {with-test & >= "1.5.0"} ] synopsis: "Irmin test suite" diff --git a/src/irmin-test/common.ml b/src/irmin-test/common.ml index 6d35c1f18a..01436177bb 100644 --- a/src/irmin-test/common.ml +++ b/src/irmin-test/common.ml @@ -130,7 +130,7 @@ module Suite = struct end module type Store_tests = functor (S : Generic_key) -> sig - val tests : (string * (Suite.t -> unit -> unit)) list + val tests : (string * (Suite.t -> unit -> unit Lwt.t)) list end module Make_helpers (S : Generic_key) = struct @@ -215,48 +215,47 @@ module Make_helpers (S : Generic_key) = struct let run (x : Suite.t) test = let repo_ptr = ref None in let config_ptr = ref None in - Lwt_main.run - (Lwt.catch - (fun () -> - let module Conf = Irmin.Backend.Conf in - let generate_random_root config = - let id = Random.int 100 |> string_of_int in - let root_value = - match Conf.find_root config with - | None -> "test_" ^ id - | Some v -> v ^ "_" ^ id - in - let root_key = Conf.(root (spec config)) in - Conf.add config root_key root_value - in - let config = generate_random_root x.config in - config_ptr := Some config; - let* () = x.init ~config in - let* repo = S.Repo.v config in - repo_ptr := Some repo; - let* () = test repo in - let* () = - (* [test] might have already closed the repo. That - [ignore_thunk_errors] shall be removed as soon as all stores - support double closes. *) - ignore_thunk_errors (fun () -> S.Repo.close repo) - in - x.clean ~config) - (fun exn -> - (* [test] failed, attempt an errorless cleanup and forward the right - backtrace to the user. *) - let bt = Printexc.get_raw_backtrace () in - let* () = - match !repo_ptr with - | Some repo -> ignore_thunk_errors (fun () -> S.Repo.close repo) - | None -> Lwt.return_unit - in - let+ () = - match !config_ptr with - | Some config -> ignore_thunk_errors (fun () -> x.clean ~config) - | None -> Lwt.return_unit - in - Printexc.raise_with_backtrace exn bt)) + Lwt.catch + (fun () -> + let module Conf = Irmin.Backend.Conf in + let generate_random_root config = + let id = Random.int 100 |> string_of_int in + let root_value = + match Conf.find_root config with + | None -> "test_" ^ id + | Some v -> v ^ "_" ^ id + in + let root_key = Conf.(root (spec config)) in + Conf.add config root_key root_value + in + let config = generate_random_root x.config in + config_ptr := Some config; + let* () = x.init ~config in + let* repo = S.Repo.v config in + repo_ptr := Some repo; + let* () = test repo in + let* () = + (* [test] might have already closed the repo. That + [ignore_thunk_errors] shall be removed as soon as all stores + support double closes. *) + ignore_thunk_errors (fun () -> S.Repo.close repo) + in + x.clean ~config) + (fun exn -> + (* [test] failed, attempt an errorless cleanup and forward the right + backtrace to the user. *) + let bt = Printexc.get_raw_backtrace () in + let* () = + match !repo_ptr with + | Some repo -> ignore_thunk_errors (fun () -> S.Repo.close repo) + | None -> Lwt.return_unit + in + let+ () = + match !config_ptr with + | Some config -> ignore_thunk_errors (fun () -> x.clean ~config) + | None -> Lwt.return_unit + in + Printexc.raise_with_backtrace exn bt) end let filter_src src = @@ -319,3 +318,7 @@ let check_raises_lwt msg exn (type a) (f : unit -> a Lwt.t) = msg (Printexc.to_string exn) (Printexc.to_string e)) module T = Irmin.Type + +module type Sleep = sig + val sleep : float -> unit Lwt.t +end diff --git a/src/irmin-test/dune b/src/irmin-test/dune index 7c5d149267..7fbcdc1c45 100644 --- a/src/irmin-test/dune +++ b/src/irmin-test/dune @@ -5,14 +5,13 @@ (preprocess (pps ppx_irmin.internal)) (libraries - alcotest + alcotest-lwt astring fmt irmin jsonm logs.fmt lwt - lwt.unix mtime mtime.clock.os) (instrumentation diff --git a/src/irmin-test/irmin_test.mli b/src/irmin-test/irmin_test.mli index d5aa465ecf..52fa646d48 100644 --- a/src/irmin-test/irmin_test.mli +++ b/src/irmin-test/irmin_test.mli @@ -65,9 +65,10 @@ module Store : sig string -> ?slow:bool -> ?random_seed:int -> - misc:unit Alcotest.test list -> + sleep:(float -> unit Lwt.t) -> + misc:unit Alcotest_lwt.test list -> (Alcotest.speed_level * Suite.t) list -> - unit + unit Lwt.t end module Node = Node diff --git a/src/irmin-test/store.ml b/src/irmin-test/store.ml index de040fb062..7d2a84d018 100644 --- a/src/irmin-test/store.ml +++ b/src/irmin-test/store.ml @@ -2412,9 +2412,9 @@ module Make (S : Generic_key) = struct S.Backend.Repo.close repo in (* Test collisions with the empty node (and its commit), *) - run x (test @@ fun () -> S.Tree.empty () |> Lwt.return); + let* () = run x (test @@ fun () -> S.Tree.empty () |> Lwt.return) in (* with a length one node, *) - run x (test @@ fun () -> add_entries (S.Tree.empty ()) 1); + run x (test @@ fun () -> add_entries (S.Tree.empty ()) 1) >>= fun () -> (* and with a length >256 node (which is the threshold for unstable inodes in irmin pack). *) run x (test @@ fun () -> add_entries (S.Tree.empty ()) 260) @@ -2427,11 +2427,14 @@ let suite' l ?(prefix = "") (_, x) = let when_ b x = if b then x else [] -let suite (speed, x) = +let suite sleep (speed, x) = let (module S) = Suite.store_generic_key x in + let module Zzz = struct + let sleep = sleep + end in let module T = Make (S) in let module T_graph = Store_graph.Make (S) in - let module T_watch = Store_watch.Make (Log) (S) in + let module T_watch = Store_watch.Make (Log) (Zzz) (S) in let with_tree_enabled = (* Disabled for flakiness. See https://github.com/mirage/irmin/issues/1090. *) not @@ -2494,7 +2497,7 @@ let slow_suite (speed, x) = ] (speed, x) -let run name ?(slow = false) ?random_seed ~misc tl = +let run name ?(slow = false) ?random_seed ~sleep ~misc tl = let () = match random_seed with | Some x -> Random.init x @@ -2503,6 +2506,6 @@ let run name ?(slow = false) ?random_seed ~misc tl = Printexc.record_backtrace true; (* Ensure that failures occuring in async lwt threads are raised. *) (Lwt.async_exception_hook := fun exn -> raise exn); - let tl1 = List.map suite tl in + let tl1 = List.map (suite sleep) tl in let tl1 = if slow then tl1 @ List.map slow_suite tl else tl1 in - Alcotest.run name (misc @ tl1) + Alcotest_lwt.run name (misc @ tl1) diff --git a/src/irmin-test/store.mli b/src/irmin-test/store.mli index 6cf39bfb5e..57aeeb89dc 100644 --- a/src/irmin-test/store.mli +++ b/src/irmin-test/store.mli @@ -18,6 +18,7 @@ val run : string -> ?slow:bool -> ?random_seed:int -> - misc:unit Alcotest.test list -> + sleep:(float -> unit Lwt.t) -> + misc:unit Alcotest_lwt.test list -> (Alcotest.speed_level * Common.t) list -> - unit + unit Lwt.t diff --git a/src/irmin-test/store_watch.ml b/src/irmin-test/store_watch.ml index 204b42fa87..eb14afc329 100644 --- a/src/irmin-test/store_watch.ml +++ b/src/irmin-test/store_watch.ml @@ -17,12 +17,16 @@ open! Import open Common -module Make (Log : Logs.LOG) (S : Generic_key) = struct +module type Sleep = sig + val sleep : float -> unit Lwt.t +end + +module Make (Log : Logs.LOG) (Zzz : Sleep) (S : Generic_key) = struct include Common.Make_helpers (S) let sleep ?(sleep_t = 0.01) () = let sleep_t = min sleep_t 1. in - Lwt.pause () >>= fun () -> Lwt_unix.sleep sleep_t + Lwt.pause () >>= fun () -> Zzz.sleep sleep_t let now_s () = Mtime.Span.to_s (Mtime_clock.elapsed ()) @@ -193,9 +197,7 @@ module Make (Log : Logs.LOG) (S : Generic_key) = struct let process ?sleep_t t head = let* () = - match sleep_t with - | None -> Lwt.return_unit - | Some s -> Lwt_unix.sleep s + match sleep_t with None -> Lwt.return_unit | Some s -> Zzz.sleep s in let () = match head with diff --git a/src/irmin-test/store_watch.mli b/src/irmin-test/store_watch.mli index 5baae0e907..52f253c7bb 100644 --- a/src/irmin-test/store_watch.mli +++ b/src/irmin-test/store_watch.mli @@ -14,4 +14,4 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. *) -module Make (_ : Logs.LOG) : Common.Store_tests +module Make (_ : Logs.LOG) (_ : Common.Sleep) : Common.Store_tests diff --git a/test/irmin-chunk/test.ml b/test/irmin-chunk/test.ml index 94c8d9df41..eef06a60f2 100644 --- a/test/irmin-chunk/test.ml +++ b/test/irmin-chunk/test.ml @@ -22,7 +22,7 @@ let key_t : Test_chunk.Key.t Alcotest.testable = (module Test_chunk.Key) let value_t : Test_chunk.Value.t Alcotest.testable = (module Test_chunk.Value) let run f () = - Lwt_main.run (f ()); + let+ () = f () in flush stderr; flush stdout @@ -77,5 +77,7 @@ let stable = ] ) let () = - Irmin_test.Store.run "irmin-chunk" ~slow:true ~misc:[ simple; stable ] - [ (`Quick, Test_chunk.suite) ] + Lwt_main.run + @@ Irmin_test.Store.run "irmin-chunk" ~slow:true ~misc:[ simple; stable ] + ~sleep:Lwt_unix.sleep + [ (`Quick, Test_chunk.suite) ] diff --git a/test/irmin-fs/dune b/test/irmin-fs/dune index 8a25710472..87614dbcb5 100644 --- a/test/irmin-fs/dune +++ b/test/irmin-fs/dune @@ -11,7 +11,7 @@ (executable (name test) (modules test) - (libraries alcotest irmin irmin-test test_fs)) + (libraries alcotest lwt.unix irmin irmin-test test_fs)) (executable (name test_unix) diff --git a/test/irmin-fs/test.ml b/test/irmin-fs/test.ml index daa5b5fd09..2ab8c18fce 100644 --- a/test/irmin-fs/test.ml +++ b/test/irmin-fs/test.ml @@ -15,5 +15,6 @@ *) let () = - Irmin_test.Store.run "irmin-fs" ~slow:true ~misc:[] - [ (`Quick, Test_fs.suite) ] + Lwt_main.run + @@ Irmin_test.Store.run "irmin-fs" ~slow:true ~misc:[] ~sleep:Lwt_unix.sleep + [ (`Quick, Test_fs.suite) ] diff --git a/test/irmin-fs/test_unix.ml b/test/irmin-fs/test_unix.ml index ab79823908..1bc071b639 100644 --- a/test/irmin-fs/test_unix.ml +++ b/test/irmin-fs/test_unix.ml @@ -15,5 +15,7 @@ *) let () = - Irmin_test.Store.run "irmin-fs.unix" ~slow:false ~misc:[] - [ (`Quick, Test_fs_unix.suite) ] + Lwt_main.run + @@ Irmin_test.Store.run "irmin-fs.unix" ~slow:false ~sleep:Lwt_unix.sleep + ~misc:[] + [ (`Quick, Test_fs_unix.suite) ] diff --git a/test/irmin-git/test.ml b/test/irmin-git/test.ml index 3cf601fc60..154b15db4c 100644 --- a/test/irmin-git/test.ml +++ b/test/irmin-git/test.ml @@ -17,5 +17,6 @@ let misc = [ ("misc", Test_git.(misc mem)) ] let () = - Irmin_test.Store.run "irmin-git" ~slow:true ~misc - [ (`Quick, Test_git.suite); (`Quick, Test_git.suite_generic) ] + Lwt_main.run + @@ Irmin_test.Store.run "irmin-git" ~slow:true ~misc ~sleep:Lwt_unix.sleep + [ (`Quick, Test_git.suite); (`Quick, Test_git.suite_generic) ] diff --git a/test/irmin-git/test_git.ml b/test/irmin-git/test_git.ml index bf00055c62..1fae8fa6cc 100644 --- a/test/irmin-git/test_git.ml +++ b/test/irmin-git/test_git.ml @@ -228,14 +228,13 @@ let misc (module S : G) = let s = (module S : S) in let g = (module S : G) in let generic = (module Generic (Irmin.Contents.String) : S) in - let run f x () = Lwt_main.run (f x) in [ - ("Testing sort order", `Quick, run test_sort_order s); - ("Testing sort order (generic)", `Quick, run test_sort_order generic); - ("Testing listing refs", `Quick, run test_list_refs g); - ("git -> mem", `Quick, run test_import_export s); - ("git blobs", `Quick, run test_blobs s); - ("git blobs of generic", `Quick, run test_blobs s); + ("Testing sort order", `Quick, fun () -> test_sort_order s); + ("Testing sort order (generic)", `Quick, fun () -> test_sort_order generic); + ("Testing listing refs", `Quick, fun () -> test_list_refs g); + ("git -> mem", `Quick, fun () -> test_import_export s); + ("git blobs", `Quick, fun () -> test_blobs s); + ("git blobs of generic", `Quick, fun () -> test_blobs s); ] let mem = (module Mem (Irmin.Contents.String) : G) diff --git a/test/irmin-git/test_git.mli b/test/irmin-git/test_git.mli index 8956cfd27a..6191323f9a 100644 --- a/test/irmin-git/test_git.mli +++ b/test/irmin-git/test_git.mli @@ -29,5 +29,5 @@ module type G = sig module Git : Irmin_git.G end -val misc : (module G) -> unit Alcotest.test_case list +val misc : (module G) -> unit Alcotest_lwt.test_case list val mem : (module G) diff --git a/test/irmin-git/test_unix.ml b/test/irmin-git/test_unix.ml index bbce7711e8..9e3157ec8f 100644 --- a/test/irmin-git/test_unix.ml +++ b/test/irmin-git/test_unix.ml @@ -16,4 +16,8 @@ let misc = [ ("misc", Test_git.misc Test_git_unix.store) ] let suites = [ (`Quick, Test_git_unix.suite) ] -let () = Irmin_test.Store.run "irmin-git.unix" ~misc ~slow:false suites + +let () = + Lwt_main.run + @@ Irmin_test.Store.run "irmin-git.unix" ~misc ~slow:false + ~sleep:Lwt_unix.sleep suites diff --git a/test/irmin-http/test.ml b/test/irmin-http/test.ml index 37955e1537..7f7f4950e2 100644 --- a/test/irmin-http/test.ml +++ b/test/irmin-http/test.ml @@ -16,4 +16,5 @@ let () = Test_http.(with_server servers) (fun () -> - Irmin_test.Store.run "irmin-http" ~misc:[] Test_http.(suites servers)) + Irmin_test.Store.run "irmin-http" ~misc:[] ~sleep:Lwt_unix.sleep + Test_http.(suites servers)) diff --git a/test/irmin-http/test_http.ml b/test/irmin-http/test_http.ml index 2af8264611..999675740a 100644 --- a/test/irmin-http/test_http.ml +++ b/test/irmin-http/test_http.ml @@ -233,6 +233,6 @@ let with_server servers f = let id = int_of_string Sys.argv.(3) in Logs.set_reporter (Irmin_test.reporter ~prefix:"S" ()); serve servers n id) - else f () + else Lwt_main.run (f ()) type test = Alcotest.speed_level * Irmin_test.Suite.t diff --git a/test/irmin-http/test_http.mli b/test/irmin-http/test_http.mli index daf5949090..f9541ffbf1 100644 --- a/test/irmin-http/test_http.mli +++ b/test/irmin-http/test_http.mli @@ -18,4 +18,4 @@ type test = Alcotest.speed_level * Irmin_test.Suite.t val servers : test list val suites : test list -> test list -val with_server : test list -> (unit -> unit) -> unit +val with_server : test list -> (unit -> unit Lwt.t) -> unit diff --git a/test/irmin-mem/dune b/test/irmin-mem/dune index 89e02a5167..1f548b95c1 100644 --- a/test/irmin-mem/dune +++ b/test/irmin-mem/dune @@ -6,7 +6,7 @@ (executable (name test) (modules test) - (libraries alcotest irmin-test test_mem)) + (libraries alcotest lwt.unix irmin-test test_mem)) (rule (alias runtest) diff --git a/test/irmin-mem/test.ml b/test/irmin-mem/test.ml index 3f03884961..e2d99e032f 100644 --- a/test/irmin-mem/test.ml +++ b/test/irmin-mem/test.ml @@ -15,5 +15,6 @@ *) let () = - Irmin_test.Store.run "irmin-mem" ~slow:true ~misc:[] - [ (`Quick, Test_mem.suite) ] + Lwt_main.run + @@ Irmin_test.Store.run "irmin-mem" ~slow:true ~misc:[] ~sleep:Lwt_unix.sleep + [ (`Quick, Test_mem.suite) ] diff --git a/test/irmin-pack/multiple_instances.ml b/test/irmin-pack/multiple_instances.ml index d7343f9ee6..93f9904a20 100644 --- a/test/irmin-pack/multiple_instances.ml +++ b/test/irmin-pack/multiple_instances.ml @@ -106,9 +106,7 @@ let ro_reload_after_close () = binding (check_binding ro c1) >>= fun () -> S.Repo.close ro let tests = - let tc name test = - Alcotest.test_case name `Quick (fun () -> Lwt_main.run (test ())) - in + let tc name test = Alcotest_lwt.test_case name `Quick (fun _switch -> test) in [ tc "Test open ro after rw closed" open_ro_after_rw_closed; tc "Test ro reload after add" ro_reload_after_add; diff --git a/test/irmin-pack/multiple_instances.mli b/test/irmin-pack/multiple_instances.mli index 2b40d2f891..4acc26805b 100644 --- a/test/irmin-pack/multiple_instances.mli +++ b/test/irmin-pack/multiple_instances.mli @@ -14,4 +14,4 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. *) -val tests : unit Alcotest.test_case list +val tests : unit Alcotest_lwt.test_case list diff --git a/test/irmin-pack/test.ml b/test/irmin-pack/test.ml index 5ff13df8d8..8b35dbfa8f 100644 --- a/test/irmin-pack/test.ml +++ b/test/irmin-pack/test.ml @@ -15,5 +15,7 @@ *) let () = - Irmin_test.Store.run "irmin-pack" ~misc:Test_pack.misc - (List.map (fun s -> (`Quick, s)) Test_pack.suite) + Lwt_main.run + @@ Irmin_test.Store.run "irmin-pack" ~misc:Test_pack.misc + ~sleep:Lwt_unix.sleep + (List.map (fun s -> (`Quick, s)) Test_pack.suite) diff --git a/test/irmin-pack/test_existing_stores.ml b/test/irmin-pack/test_existing_stores.ml index 3d99325105..aaacec2977 100644 --- a/test/irmin-pack/test_existing_stores.ml +++ b/test/irmin-pack/test_existing_stores.ml @@ -216,10 +216,10 @@ end let tests = [ - Alcotest.test_case "Test index reconstruction" `Quick (fun () -> - Lwt_main.run (Test_reconstruct.test_reconstruct ())); - Alcotest.test_case "Test integrity check" `Quick (fun () -> - Lwt_main.run (Test_corrupted_stores.test ())); - Alcotest.test_case "Test integrity check for inodes" `Quick (fun () -> - Lwt_main.run (Test_corrupted_inode.test ())); + Alcotest_lwt.test_case "Test index reconstruction" `Quick (fun _switch -> + Test_reconstruct.test_reconstruct); + Alcotest_lwt.test_case "Test integrity check" `Quick (fun _switch -> + Test_corrupted_stores.test); + Alcotest_lwt.test_case "Test integrity check for inodes" `Quick + (fun _switch -> Test_corrupted_inode.test); ] diff --git a/test/irmin-pack/test_existing_stores.mli b/test/irmin-pack/test_existing_stores.mli index 2b40d2f891..4acc26805b 100644 --- a/test/irmin-pack/test_existing_stores.mli +++ b/test/irmin-pack/test_existing_stores.mli @@ -14,4 +14,4 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. *) -val tests : unit Alcotest.test_case list +val tests : unit Alcotest_lwt.test_case list diff --git a/test/irmin-pack/test_flush_reload.ml b/test/irmin-pack/test_flush_reload.ml index 9cd6ff86f6..31e4db6351 100644 --- a/test/irmin-pack/test_flush_reload.ml +++ b/test/irmin-pack/test_flush_reload.ml @@ -247,8 +247,8 @@ let test_reload () = let tests = [ - Alcotest.test_case "Reload during flush stages" `Quick (fun () -> - Lwt_main.run (test_flush ())); - Alcotest.test_case "Flush during reload stages" `Quick (fun () -> - Lwt_main.run (test_reload ())); + Alcotest_lwt.test_case "Reload during flush stages" `Quick + (fun _switch () -> test_flush ()); + Alcotest_lwt.test_case "Flush during reload stages" `Quick + (fun _switch () -> test_reload ()); ] diff --git a/test/irmin-pack/test_gc.ml b/test/irmin-pack/test_gc.ml index 7f1a896038..ae85ca34af 100644 --- a/test/irmin-pack/test_gc.ml +++ b/test/irmin-pack/test_gc.ml @@ -30,7 +30,7 @@ let fresh_name = let name = Filename.concat test_dir ("test-gc" ^ string_of_int !c) in name -let tc name f = Alcotest.test_case name `Quick (fun () -> Lwt_main.run (f ())) +let tc name f = Alcotest_lwt.test_case name `Quick (fun _switch () -> f ()) include struct module S = struct diff --git a/test/irmin-pack/test_gc.mli b/test/irmin-pack/test_gc.mli index a00e5547f3..edf8103aed 100644 --- a/test/irmin-pack/test_gc.mli +++ b/test/irmin-pack/test_gc.mli @@ -15,9 +15,9 @@ *) module Blocking_gc : sig - val tests : unit Alcotest.test_case list + val tests : unit Alcotest_lwt.test_case list end module Concurrent_gc : sig - val tests : unit Alcotest.test_case list + val tests : unit Alcotest_lwt.test_case list end diff --git a/test/irmin-pack/test_hashes.ml b/test/irmin-pack/test_hashes.ml index 4e6ea213e8..0aecf77c8e 100644 --- a/test/irmin-pack/test_hashes.ml +++ b/test/irmin-pack/test_hashes.ml @@ -311,9 +311,7 @@ module Test_V1 = struct end let tests = - let tc name f = - Alcotest.test_case name `Quick (fun () -> Lwt_main.run (f ())) - in + let tc name f = Alcotest_lwt.test_case name `Quick (fun _switch -> f) in [ tc "contents hash" Test_tezos_conf.contents_hash; tc "inode_values hash" Test_tezos_conf.inode_values_hash; diff --git a/test/irmin-pack/test_hashes.mli b/test/irmin-pack/test_hashes.mli index 3e8b1f82b6..5502f37745 100644 --- a/test/irmin-pack/test_hashes.mli +++ b/test/irmin-pack/test_hashes.mli @@ -14,7 +14,7 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. *) -val tests : unit Alcotest.test_case list +val tests : unit Alcotest_lwt.test_case list val check_iter : string -> diff --git a/test/irmin-pack/test_inode.ml b/test/irmin-pack/test_inode.ml index aa194b22a7..e261e98723 100644 --- a/test/irmin-pack/test_inode.ml +++ b/test/irmin-pack/test_inode.ml @@ -808,7 +808,7 @@ module Child_ordering = struct assert (chosen_bit = 0 || chosen_bit = 1); chosen_bit - let test_seeded_hash () = + let test_seeded_hash _switch () = let entries = Irmin_tezos.Conf.entries in let reference ~depth step = abs (Step.short_hash ~seed:depth step) mod entries @@ -825,7 +825,8 @@ module Child_ordering = struct let step = random_string 8 and depth = Random.int 10 in let expected = reference ~depth step in check_child_index __POS__ (module Order) ~expected ~step ~depth - done + done; + Lwt.return_unit let hash_bits_max_depth ~log2_entries = (* For a given [depth], the final bit of the corresponding index is at @@ -838,7 +839,7 @@ module Child_ordering = struct in aux 0 - let test_hash_bits () = + let test_hash_bits _switch () = (* [entries] is required to be a power of 2 greater than 1 and less than 2048, so we test every possible value here: *) for log2_entries = 1 to 10 do @@ -875,9 +876,10 @@ module Child_ordering = struct (module Order) ~step ~depth:(max_depth + 1) done - done + done; + Lwt.return_unit - let test_custom () = + let test_custom _switch () = let entries = 16 in let square_index ~depth step = let a = depth and b = int_of_string (Bytes.unsafe_to_string step) in @@ -887,12 +889,13 @@ module Child_ordering = struct check_child_index __POS__ (module Order) ~depth:1 ~step:"1" ~expected:1; check_child_index __POS__ (module Order) ~depth:2 ~step:"2" ~expected:4; check_child_index __POS__ (module Order) ~depth:3 ~step:"3" ~expected:9; - () + (); + Lwt.return_unit end let tests = - let tc_sync name f = Alcotest.test_case name `Quick f in - let tc name f = tc_sync name (fun () -> Lwt_main.run (f ())) in + let tc_sync name f = Alcotest_lwt.test_case name `Quick f in + let tc name f = tc_sync name (fun _switch -> f) in (* Test disabled because it relies on being able to serialise concrete inodes, which is not possible following the introduction of structured keys. *) let _ = tc "test truncated inodes" test_truncated_inodes in diff --git a/test/irmin-pack/test_inode.mli b/test/irmin-pack/test_inode.mli index 2b40d2f891..4acc26805b 100644 --- a/test/irmin-pack/test_inode.mli +++ b/test/irmin-pack/test_inode.mli @@ -14,4 +14,4 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. *) -val tests : unit Alcotest.test_case list +val tests : unit Alcotest_lwt.test_case list diff --git a/test/irmin-pack/test_pack.ml b/test/irmin-pack/test_pack.ml index 906c25b13e..228d8be3ef 100644 --- a/test/irmin-pack/test_pack.ml +++ b/test/irmin-pack/test_pack.ml @@ -177,8 +177,10 @@ module Dict = struct let tests = [ - Alcotest.test_case "dict" `Quick test_dict; - Alcotest.test_case "RO dict" `Quick test_readonly_dict; + Alcotest_lwt.test_case "dict" `Quick (fun _ () -> + Lwt.return (test_dict ())); + Alcotest_lwt.test_case "RO dict" `Quick (fun _ () -> + Lwt.return (test_readonly_dict ())); ] end @@ -399,17 +401,17 @@ module Pack = struct let tests = [ - Alcotest.test_case "pack" `Quick (fun () -> Lwt_main.run (test_pack ())); - Alcotest.test_case "RO pack" `Quick (fun () -> - Lwt_main.run (test_readonly_pack ())); - Alcotest.test_case "close" `Quick (fun () -> - Lwt_main.run (test_close_pack ())); - Alcotest.test_case "close readonly" `Quick (fun () -> - Lwt_main.run (test_close_pack_more ())); - Alcotest.test_case "readonly reload, index flush" `Quick (fun () -> - Lwt_main.run (readonly_reload_index_flush ())); - Alcotest.test_case "readonly find, index flush" `Quick (fun () -> - Lwt_main.run (readonly_find_index_flush ())); + Alcotest_lwt.test_case "pack" `Quick (fun _switch () -> test_pack ()); + Alcotest_lwt.test_case "RO pack" `Quick (fun _switch () -> + test_readonly_pack ()); + Alcotest_lwt.test_case "close" `Quick (fun _switch () -> + test_close_pack ()); + Alcotest_lwt.test_case "close readonly" `Quick (fun _switch () -> + test_close_pack_more ()); + Alcotest_lwt.test_case "readonly reload, index flush" `Quick + (fun _switch () -> readonly_reload_index_flush ()); + Alcotest_lwt.test_case "readonly find, index flush" `Quick + (fun _switch () -> readonly_find_index_flush ()); ] end @@ -487,10 +489,9 @@ module Branch = struct let tests = [ - Alcotest.test_case "branch" `Quick (fun () -> - Lwt_main.run (test_branch ())); - Alcotest.test_case "branch close" `Quick (fun () -> - Lwt_main.run (test_close_branch ())); + Alcotest_lwt.test_case "branch" `Quick (fun _switch -> test_branch); + Alcotest_lwt.test_case "branch close" `Quick (fun _switch -> + test_close_branch); ] end diff --git a/test/irmin-pack/test_pack.mli b/test/irmin-pack/test_pack.mli index e4a19a6027..599c43edf1 100644 --- a/test/irmin-pack/test_pack.mli +++ b/test/irmin-pack/test_pack.mli @@ -15,4 +15,4 @@ *) val suite : Irmin_test.Suite.t list -val misc : (string * unit Alcotest.test_case list) list +val misc : (string * unit Alcotest_lwt.test_case list) list diff --git a/test/irmin-pack/test_pack_version_bump.ml b/test/irmin-pack/test_pack_version_bump.ml index 46002f1ab8..17cb1519f5 100644 --- a/test/irmin-pack/test_pack_version_bump.ml +++ b/test/irmin-pack/test_pack_version_bump.ml @@ -156,8 +156,8 @@ let test_open_RW () : unit Lwt.t = Lwt.return () let tests = - let f g () = Lwt_main.run @@ g () in - Alcotest. + let f g _switch () = g () in + Alcotest_lwt. [ test_case "test_RO_no_migration" `Quick (f test_RO_no_migration); test_case "test_open_RW" `Quick (f test_open_RW); diff --git a/test/irmin-pack/test_pack_version_bump.mli b/test/irmin-pack/test_pack_version_bump.mli index d38ba9a90a..01604e1617 100644 --- a/test/irmin-pack/test_pack_version_bump.mli +++ b/test/irmin-pack/test_pack_version_bump.mli @@ -1 +1 @@ -val tests : unit Alcotest.test_case list +val tests : unit Alcotest_lwt.test_case list diff --git a/test/irmin-pack/test_snapshot.ml b/test/irmin-pack/test_snapshot.ml index 3be7401fb0..f0cb79b1c6 100644 --- a/test/irmin-pack/test_snapshot.ml +++ b/test/irmin-pack/test_snapshot.ml @@ -251,9 +251,7 @@ let test_gced_store_on_disk () = S.Repo.close repo_import let tests = - let tc name f = - Alcotest.test_case name `Quick (fun () -> Lwt_main.run (f ())) - in + let tc name f = Alcotest_lwt.test_case name `Quick (fun _switch () -> f ()) in [ tc "in memory minimal" test_in_memory_minimal; tc "in memory always" test_in_memory_always; diff --git a/test/irmin-pack/test_tree.ml b/test/irmin-pack/test_tree.ml index c03836e70f..42ecbf3d93 100644 --- a/test/irmin-pack/test_tree.ml +++ b/test/irmin-pack/test_tree.ml @@ -694,28 +694,28 @@ let test_reexport_node () = let tests = [ - Alcotest.test_case "fold over keys in sorted order" `Quick (fun () -> - Lwt_main.run (test_fold_sorted ())); - Alcotest.test_case "fold over keys in random order" `Quick (fun () -> - Lwt_main.run (test_fold_random ())); - Alcotest.test_case "fold over keys in undefined order" `Quick (fun () -> - Lwt_main.run (test_fold_undefined ())); - Alcotest.test_case "test Merkle proof for large inodes" `Quick (fun () -> - Lwt_main.run (test_large_inode ())); - Alcotest.test_case "test Merkle proof for small inodes" `Quick (fun () -> - Lwt_main.run (test_small_inode ())); - Alcotest.test_case "test deeper Merkle proof" `Quick (fun () -> - Lwt_main.run (test_deeper_proof ())); - Alcotest.test_case "test large Merkle proof" `Slow (fun () -> - Lwt_main.run (test_large_proofs ())); - Alcotest.test_case "test extenders in stream proof" `Quick (fun () -> - Lwt_main.run (test_extenders ())); - Alcotest.test_case "test hardcoded stream proof" `Quick (fun () -> - Lwt_main.run (test_hardcoded_stream ())); - Alcotest.test_case "test hardcoded proof" `Quick (fun () -> - Lwt_main.run (test_hardcoded_proof ())); - Alcotest.test_case "test stream proof exn" `Quick (fun () -> - Lwt_main.run (test_proof_exn ())); - Alcotest.test_case "test reexport node" `Quick (fun () -> - Lwt_main.run (test_reexport_node ())); + Alcotest_lwt.test_case "fold over keys in sorted order" `Quick + (fun _switch -> test_fold_sorted); + Alcotest_lwt.test_case "fold over keys in random order" `Quick + (fun _switch -> test_fold_random); + Alcotest_lwt.test_case "fold over keys in undefined order" `Quick + (fun _switch -> test_fold_undefined); + Alcotest_lwt.test_case "test Merkle proof for large inodes" `Quick + (fun _switch -> test_large_inode); + Alcotest_lwt.test_case "test Merkle proof for small inodes" `Quick + (fun _switch -> test_small_inode); + Alcotest_lwt.test_case "test deeper Merkle proof" `Quick (fun _switch -> + test_deeper_proof); + Alcotest_lwt.test_case "test large Merkle proof" `Slow (fun _switch -> + test_large_proofs); + Alcotest_lwt.test_case "test extenders in stream proof" `Quick + (fun _switch -> test_extenders); + Alcotest_lwt.test_case "test hardcoded stream proof" `Quick (fun _switch -> + test_hardcoded_stream); + Alcotest_lwt.test_case "test hardcoded proof" `Quick (fun _switch -> + test_hardcoded_proof); + Alcotest_lwt.test_case "test stream proof exn" `Quick (fun _switch -> + test_proof_exn); + Alcotest_lwt.test_case "test reexport node" `Quick (fun _switch -> + test_reexport_node); ] diff --git a/test/irmin-pack/test_upgrade.ml b/test/irmin-pack/test_upgrade.ml index 11f3a253b2..4bd42a3406 100644 --- a/test/irmin-pack/test_upgrade.ml +++ b/test/irmin-pack/test_upgrade.ml @@ -675,10 +675,10 @@ let test start_mode () = (** Product on start_mode *) let tests = [ - Alcotest.test_case "upgrade From_v3" `Quick (fun () -> - Lwt_main.run (test From_v3 ())); - Alcotest.test_case "upgrade From_v2" `Quick (fun () -> - Lwt_main.run (test From_v2 ())); - Alcotest.test_case "upgrade From_scratch" `Quick (fun () -> - Lwt_main.run (test From_scratch ())); + Alcotest_lwt.test_case "upgrade From_v3" `Quick (fun _switch () -> + test From_v3 ()); + Alcotest_lwt.test_case "upgrade From_v2" `Quick (fun _switch () -> + test From_v2 ()); + Alcotest_lwt.test_case "upgrade From_scratch" `Quick (fun _switch () -> + test From_scratch ()); ] diff --git a/test/irmin/dune b/test/irmin/dune index b1beacea1e..219309ffdf 100644 --- a/test/irmin/dune +++ b/test/irmin/dune @@ -11,6 +11,7 @@ alcotest alcotest-lwt lwt + lwt.unix hex logs logs.fmt)) diff --git a/test/irmin/generic-key/dune b/test/irmin/generic-key/dune index d1f7df1dad..96e1b41b09 100644 --- a/test/irmin/generic-key/dune +++ b/test/irmin/generic-key/dune @@ -4,4 +4,12 @@ (package irmin-test) (preprocess (pps ppx_irmin.internal)) - (libraries irmin irmin.mem irmin-test alcotest alcotest-lwt lwt vector)) + (libraries + irmin + irmin.mem + irmin-test + alcotest + alcotest-lwt + lwt + lwt.unix + vector)) diff --git a/test/irmin/generic-key/test.ml b/test/irmin/generic-key/test.ml index b945778c5d..28f52b7cea 100644 --- a/test/irmin/generic-key/test.ml +++ b/test/irmin/generic-key/test.ml @@ -15,5 +15,8 @@ *) let () = - Irmin_test.Store.run __FILE__ ~slow:true ~misc:[] - [ (`Quick, Test_store_offset.suite); (`Quick, Test_inlined_contents.suite) ] + Lwt_main.run + @@ Irmin_test.Store.run __FILE__ ~slow:true ~misc:[] ~sleep:Lwt_unix.sleep + [ + (`Quick, Test_store_offset.suite); (`Quick, Test_inlined_contents.suite); + ]