From 9b04ced7bf2bef3db50eb050363d120105443aba Mon Sep 17 00:00:00 2001 From: Arvid Jakobsson Date: Thu, 23 Mar 2023 15:11:49 +0100 Subject: [PATCH] Revert "Merge tezos/tezos!7997: p2p: port all tests to alcotezt" This reverts commit 7268205fa6a624f4ea1f5b11fa63f0dfed4b5b57, reversing changes made to 8db901855ba11a4602faa3efc30cb011306db6ab. --- manifest/main.ml | 75 ++++++++++++- opam/tezos-base-test-helpers.opam | 3 +- opam/tezos-event-logging-test-helpers.opam | 2 +- opam/tezos-p2p.opam | 4 +- src/lib_base/test_helpers/dune | 6 +- src/lib_event_logging/test_helpers/dune | 5 +- src/lib_p2p/test/common/node.ml | 2 - src/lib_p2p/test/common/node.mli | 2 - src/lib_p2p/test/common/process.ml | 12 +-- src/lib_p2p/test/dune | 106 +++++++++++++------ src/lib_p2p/test/test_p2p_banned_peers.ml | 2 +- src/lib_p2p/test/test_p2p_broadcast.ml | 28 ++--- src/lib_p2p/test/test_p2p_buffer_reader.ml | 2 +- src/lib_p2p/test/test_p2p_connect_handler.ml | 2 +- src/lib_p2p/test/test_p2p_io_scheduler.ml | 12 +-- src/lib_p2p/test/test_p2p_maintenance.ml | 4 +- src/lib_p2p/test/test_p2p_node.ml | 4 +- src/lib_p2p/test/test_p2p_peerset.ml | 2 +- src/lib_p2p/test/test_p2p_pool.ml | 64 +++++------ src/lib_p2p/test/test_p2p_socket.ml | 4 +- tezt/lib_alcotezt/alcotest.ml | 13 +-- tezt/lib_alcotezt/alcotest.mli | 16 +-- tezt/tests/dune | 1 - 23 files changed, 225 insertions(+), 146 deletions(-) diff --git a/manifest/main.ml b/manifest/main.ml index 6908ced49ff7..aabde1cf43a2 100644 --- a/manifest/main.ml +++ b/manifest/main.ml @@ -1019,7 +1019,7 @@ let octez_event_logging_test_helpers = octez_error_monad |> open_ |> open_ ~m:"TzLwtreslib"; octez_event_logging |> open_; octez_test_helpers |> open_; - alcotezt; + alcotest; ] ~js_compatible:true ~linkall:true @@ -1253,12 +1253,12 @@ let octez_base_test_helpers = octez_stdlib_unix; octez_event_logging_test_helpers; octez_test_helpers |> open_; - alcotezt; + alcotest; + alcotest_lwt; qcheck_alcotest; ] ~linkall:true ~bisect_ppx:No - ~release_status:Released let lazy_containers = public_lib @@ -1651,7 +1651,7 @@ let _octez_p2p_tezt = ] let _octez_p2p_tests = - tezt + tests [ "test_p2p_socket"; "test_p2p_pool"; @@ -1682,9 +1682,74 @@ let _octez_p2p_tests = octez_p2p_test_common |> open_; octez_p2p_services |> open_; tezt_tezos; - alcotezt; + alcotest_lwt; astring; ] + ~linkall:true + ~alias:"" + ~dune: + Dune.( + (* At the termination of the tests, or if an unexpected + error occurs, detached processes are terminated through a + SIGKILL. + See https://github.com/aantron/bisect_ppx/blob/master/doc/advanced.md#SIGTERM + See https://gitlab.com/tezos/tezos/-/issues/1946 *) + let run_exe prog args = + setenv "BISECT_SIGTERM" "yes" @@ run_exe prog args + in + [ + alias_rule + "runtest_p2p_pool" + ~locks:"/ports/49152-65535" + ~action:(run_exe "test_p2p_pool" []); + alias_rule + "runtest_p2p_broadcast" + ~locks:"/ports/49152-65535" + ~action:(run_exe "test_p2p_broadcast" []); + alias_rule + "runtest_p2p_io_scheduler" + ~locks:"/ports/49152-65535" + ~action:(run_exe "test_p2p_io_scheduler" []); + alias_rule + "runtest_p2p_socket" + ~locks:"/ports/49152-65535" + ~action:(run_exe "test_p2p_socket" []); + alias_rule + "runtest_p2p_node" + ~locks:"/ports/49152-65535" + ~action:(run_exe "test_p2p_node" []); + alias_rule + "runtest_p2p_peerset" + ~action:(run_exe "test_p2p_peerset" []); + alias_rule + "runtest_p2p_buffer_reader" + ~action:(run_exe "test_p2p_buffer_reader" []); + alias_rule + "runtest_p2p_banned_peers" + ~action:(run_exe "test_p2p_banned_peers" []); + alias_rule + "runtest_p2p_connect_handler" + ~action:(run_exe "test_p2p_connect_handler" []); + alias_rule + "runtest_p2p_maintenance" + ~action:(run_exe "test_p2p_maintenance" []); + alias_rule + "runtest" + ~package:"tezos-p2p" + ~alias_deps: + [ + "runtest_p2p_socket"; + "runtest_p2p_pool"; + "runtest_p2p_broadcast"; + "runtest_p2p_io_scheduler"; + "runtest_p2p_peerset"; + "runtest_p2p_buffer_reader"; + "runtest_p2p_banned_peers"; + "runtest_p2p_node"; + "runtest_p2p_connect_handler"; + "runtest_p2p_maintenance"; + ]; + ]) let octez_gossipsub = public_lib diff --git a/opam/tezos-base-test-helpers.opam b/opam/tezos-base-test-helpers.opam index af84036676ee..b90aaa1d71d2 100644 --- a/opam/tezos-base-test-helpers.opam +++ b/opam/tezos-base-test-helpers.opam @@ -14,7 +14,8 @@ depends: [ "tezos-stdlib-unix" "tezos-event-logging-test-helpers" "tezos-test-helpers" - "octez-alcotezt" + "alcotest" { >= "1.5.0" } + "alcotest-lwt" { >= "1.5.0" } "qcheck-alcotest" { >= "0.20" } ] build: [ diff --git a/opam/tezos-event-logging-test-helpers.opam b/opam/tezos-event-logging-test-helpers.opam index da842a3c3272..a7c013a54a95 100644 --- a/opam/tezos-event-logging-test-helpers.opam +++ b/opam/tezos-event-logging-test-helpers.opam @@ -16,7 +16,7 @@ depends: [ "tezos-error-monad" "tezos-event-logging" "tezos-test-helpers" - "octez-alcotezt" + "alcotest" { >= "1.5.0" } ] build: [ ["rm" "-r" "vendors"] diff --git a/opam/tezos-p2p.opam b/opam/tezos-p2p.opam index ea08cbfb3638..50bafcf58fe4 100644 --- a/opam/tezos-p2p.opam +++ b/opam/tezos-p2p.opam @@ -20,13 +20,13 @@ depends: [ "tezos-p2p-services" "tezos-version" "prometheus" { >= "1.2" } - "tezt" { with-test & >= "3.0.0" } "tezos-test-helpers" {with-test} "tezos-base-test-helpers" {with-test} "tezos-event-logging-test-helpers" {with-test} "tezt-tezos" {with-test} - "octez-alcotezt" {with-test} + "alcotest-lwt" { with-test & >= "1.5.0" } "astring" {with-test} + "tezt" { with-test & >= "3.0.0" } ] build: [ ["rm" "-r" "vendors"] diff --git a/src/lib_base/test_helpers/dune b/src/lib_base/test_helpers/dune index 7484d79600a7..05c6ec897486 100644 --- a/src/lib_base/test_helpers/dune +++ b/src/lib_base/test_helpers/dune @@ -10,11 +10,11 @@ tezos-stdlib-unix tezos-event-logging-test-helpers tezos-test-helpers - octez-alcotezt + alcotest + alcotest-lwt qcheck-alcotest) (library_flags (:standard -linkall)) (flags (:standard) -open Tezos_base.TzPervasives - -open Tezos_test_helpers - -open Octez_alcotezt)) + -open Tezos_test_helpers)) diff --git a/src/lib_event_logging/test_helpers/dune b/src/lib_event_logging/test_helpers/dune index 430c01590019..a5049f113411 100644 --- a/src/lib_event_logging/test_helpers/dune +++ b/src/lib_event_logging/test_helpers/dune @@ -11,7 +11,7 @@ tezos-error-monad tezos-event-logging tezos-test-helpers - octez-alcotezt) + alcotest) (js_of_ocaml) (library_flags (:standard -linkall)) (flags @@ -19,5 +19,4 @@ -open Tezos_error_monad -open Tezos_error_monad.TzLwtreslib -open Tezos_event_logging - -open Tezos_test_helpers - -open Octez_alcotezt)) + -open Tezos_test_helpers)) diff --git a/src/lib_p2p/test/common/node.ml b/src/lib_p2p/test/common/node.ml index ee42b2f2f03a..c07a8166d91f 100644 --- a/src/lib_p2p/test/common/node.ml +++ b/src/lib_p2p/test/common/node.ml @@ -293,8 +293,6 @@ let select_nth_point n points = in loop n [] points -let default_ipv6_addr = Ipaddr.V6.localhost - let gen_points npoints ?port addr = match port with | Some port -> diff --git a/src/lib_p2p/test/common/node.mli b/src/lib_p2p/test/common/node.mli index a5f33df32451..48e175051003 100644 --- a/src/lib_p2p/test/common/node.mli +++ b/src/lib_p2p/test/common/node.mli @@ -56,8 +56,6 @@ type t = { (** [sync node] join [node] to a synchronization barrier. *) val sync : t -> unit tzresult Lwt.t -val default_ipv6_addr : P2p_addr.t - (** [gen_points npoints ~port addr] generated [npoints] points. If [port] is not specified, it loops and generates points randomly until it finds [npoints] that are not currently used. diff --git a/src/lib_p2p/test/common/process.ml b/src/lib_p2p/test/common/process.ml index 495c1e0f81cc..e3ff33308257 100644 --- a/src/lib_p2p/test/common/process.ml +++ b/src/lib_p2p/test/common/process.ml @@ -35,13 +35,9 @@ let log_f ~level format = Format.ikfprintf (fun _ -> Lwt.return_unit) Format.std_formatter format else Format.kasprintf (fun msg -> Lwt_log.log ~section ~level msg) format -(* not used at the moment *) -let _lwt_log_notice fmt = log_f ~level:Lwt_log.Notice fmt +let lwt_log_notice fmt = log_f ~level:Lwt_log.Notice fmt -(* not used at the moment *) -let _lwt_log_info fmt = log_f ~level:Lwt_log.Info fmt - -let lwt_log_debug fmt = log_f ~level:Lwt_log.Debug fmt +let lwt_log_info fmt = log_f ~level:Lwt_log.Info fmt let lwt_log_error fmt = log_f ~level:Lwt_log.Error fmt @@ -245,7 +241,7 @@ let detach ?(prefix = "") ?canceler ?input_encoding ?output_encoding ~close_mode:`Keep ~channel:Lwt_io.stderr () ; - let* () = lwt_log_debug "PID: %d" (Unix.getpid ()) in + let* () = lwt_log_notice "PID: %d" (Unix.getpid ()) in handle_result ~value_encoding ~flags @@ -446,7 +442,7 @@ let wait_all_results (processes : ('a, 'b, 'c) t list) = let* o = loop terminations in match o with | None -> ( - let* () = lwt_log_debug "All done!" in + let* () = lwt_log_info "All done!" in let* terminated = all terminations in match List.partition_result terminated with | _, _ :: _ -> assert false diff --git a/src/lib_p2p/test/dune b/src/lib_p2p/test/dune index 32c8bfc3c514..35cfff9d0e3d 100644 --- a/src/lib_p2p/test/dune +++ b/src/lib_p2p/test/dune @@ -1,11 +1,19 @@ ; This file was automatically generated, do not edit. ; Edit file manifest/main.ml instead. -(library - (name src_lib_p2p_test_tezt_lib) - (instrumentation (backend bisect_ppx)) +(executables + (names + test_p2p_socket + test_p2p_pool + test_p2p_broadcast + test_p2p_io_scheduler + test_p2p_peerset + test_p2p_buffer_reader + test_p2p_banned_peers + test_p2p_node + test_p2p_connect_handler + test_p2p_maintenance) (libraries - tezt.core tezos-base tezos-base.unix tezos-stdlib-unix @@ -17,13 +25,13 @@ tezos_p2p_test_common tezos-p2p-services tezt-tezos - octez-alcotezt + alcotest-lwt astring) - (library_flags (:standard -linkall)) + (link_flags + (:standard) + (-linkall)) (flags (:standard) - -open Tezt_core - -open Tezt_core.Base -open Tezos_base.TzPervasives -open Tezos_stdlib_unix -open Tezos_stdlib @@ -32,30 +40,66 @@ -open Tezos_base_test_helpers -open Tezos_event_logging_test_helpers -open Tezos_p2p_test_common - -open Tezos_p2p_services - -open Octez_alcotezt) - (modules - test_p2p_socket - test_p2p_pool - test_p2p_broadcast - test_p2p_io_scheduler - test_p2p_peerset - test_p2p_buffer_reader - test_p2p_banned_peers - test_p2p_node - test_p2p_connect_handler - test_p2p_maintenance)) + -open Tezos_p2p_services)) -(executable - (name main) - (instrumentation (backend bisect_ppx --bisect-sigterm)) - (libraries - src_lib_p2p_test_tezt_lib - tezt) - (modules main)) +(rule + (alias runtest_p2p_pool) + (locks /ports/49152-65535) + (action (setenv BISECT_SIGTERM yes (run %{exe:test_p2p_pool.exe})))) + +(rule + (alias runtest_p2p_broadcast) + (locks /ports/49152-65535) + (action (setenv BISECT_SIGTERM yes (run %{exe:test_p2p_broadcast.exe})))) + +(rule + (alias runtest_p2p_io_scheduler) + (locks /ports/49152-65535) + (action (setenv BISECT_SIGTERM yes (run %{exe:test_p2p_io_scheduler.exe})))) + +(rule + (alias runtest_p2p_socket) + (locks /ports/49152-65535) + (action (setenv BISECT_SIGTERM yes (run %{exe:test_p2p_socket.exe})))) + +(rule + (alias runtest_p2p_node) + (locks /ports/49152-65535) + (action (setenv BISECT_SIGTERM yes (run %{exe:test_p2p_node.exe})))) -(rule (alias runtezt) (package tezos-p2p) (action (run %{dep:./main.exe}))) +(rule + (alias runtest_p2p_peerset) + (action (setenv BISECT_SIGTERM yes (run %{exe:test_p2p_peerset.exe})))) + +(rule + (alias runtest_p2p_buffer_reader) + (action (setenv BISECT_SIGTERM yes (run %{exe:test_p2p_buffer_reader.exe})))) + +(rule + (alias runtest_p2p_banned_peers) + (action (setenv BISECT_SIGTERM yes (run %{exe:test_p2p_banned_peers.exe})))) + +(rule + (alias runtest_p2p_connect_handler) + (action + (setenv BISECT_SIGTERM yes (run %{exe:test_p2p_connect_handler.exe})))) + +(rule + (alias runtest_p2p_maintenance) + (action (setenv BISECT_SIGTERM yes (run %{exe:test_p2p_maintenance.exe})))) (rule - (targets main.ml) - (action (with-stdout-to %{targets} (echo "let () = Tezt.Test.run ()")))) + (alias runtest) + (package tezos-p2p) + (deps + (alias runtest_p2p_socket) + (alias runtest_p2p_pool) + (alias runtest_p2p_broadcast) + (alias runtest_p2p_io_scheduler) + (alias runtest_p2p_peerset) + (alias runtest_p2p_buffer_reader) + (alias runtest_p2p_banned_peers) + (alias runtest_p2p_node) + (alias runtest_p2p_connect_handler) + (alias runtest_p2p_maintenance)) + (action (progn))) diff --git a/src/lib_p2p/test/test_p2p_banned_peers.ml b/src/lib_p2p/test/test_p2p_banned_peers.ml index 8b42dc6050a7..7bad6c360472 100644 --- a/src/lib_p2p/test/test_p2p_banned_peers.ml +++ b/src/lib_p2p/test/test_p2p_banned_peers.ml @@ -26,7 +26,7 @@ (** Testing ------- Component: P2P - Invocation: dune exec src/lib_p2p/test/main.exe + Invocation: dune build @src/lib_p2p/test/runtest_p2p_banned_peers Subject: On banning peers and usage of Access Control Lists (ACL) using sets and POSIX timestamps. *) diff --git a/src/lib_p2p/test/test_p2p_broadcast.ml b/src/lib_p2p/test/test_p2p_broadcast.ml index dc140c6741d3..d6e26e7f54a6 100644 --- a/src/lib_p2p/test/test_p2p_broadcast.ml +++ b/src/lib_p2p/test/test_p2p_broadcast.ml @@ -26,7 +26,7 @@ (** Testing ------- Component: P2P - Invocation: dune exec src/lib_p2p/test/main.exe + Invocation: dune build @src/lib_p2p/test/runtest_p2p_broadcast Dependencies: src/lib_p2p/test/process.ml Subject: Testing of the Broadcast Each test launches nodes in separate process, each node @@ -92,7 +92,7 @@ module Simple = struct let rec connect ~timeout connect_handler pool point = let open Lwt_syntax in - let* () = lwt_debug "Connect to %a" P2p_point.Id.pp point in + let* () = lwt_log_info "Connect to %a" P2p_point.Id.pp point in let* r = P2p_connect_handler.connect connect_handler point ~timeout in match r with | Error (Tezos_p2p_services.P2p_errors.Connected :: _) -> ( @@ -107,7 +107,7 @@ module Simple = struct | Timeout | Tezos_p2p_services.P2p_errors.Rejected _ ) as head_err) :: _) -> let* () = - lwt_debug + lwt_log_info "Connection to %a failed (%a)@." P2p_point.Id.pp point @@ -219,7 +219,7 @@ module Simple = struct node.pool node.points in - let*! () = lwt_debug "Bootstrap OK@." in + let*! () = lwt_log_info "Bootstrap OK@." in let* () = Node.sync node in let rec loop n acc gacc msg = if n <= 0 then return (acc, gacc) @@ -233,10 +233,10 @@ module Simple = struct let end_time = Ptime_clock.now () in let span = Ptime.diff end_time start_time in let*! () = - lwt_debug "Broadcast message in %a.@." Ptime.Span.pp span + lwt_log_info "Broadcast message in %a.@." Ptime.Span.pp span in let* () = Node.sync node in - let*! () = lwt_debug "Wait others.@." in + let*! () = lwt_log_info "Wait others.@." in let* () = Node.sync node in let end_global_time = Ptime_clock.now () in let gspan = Ptime.diff end_global_time start_global_time in @@ -249,7 +249,7 @@ module Simple = struct let* times, gtimes = loop repeat [] [] msgs in let print_stat times name = let ftimes = List.map Ptime.Span.to_float_s times in - lwt_debug + lwt_log_notice "%s; %f; %f; %f; %f; %f" name (List.fold_left Float.max Float.min_float ftimes) @@ -259,8 +259,8 @@ module Simple = struct (stddev ftimes) in let*! () = close_all node.pool in - let*! () = lwt_debug "All connections successfully closed.@." in - let*! () = lwt_debug "type; max; min; avg; median; std_dev" in + let*! () = lwt_log_info "All connections successfully closed.@." in + let*! () = lwt_log_notice "type; max; min; avg; median; std_dev" in let*! () = print_stat times "broadcasting" in let*! () = print_stat gtimes "global" in @@ -268,7 +268,7 @@ module Simple = struct let node msgs (node : Node.t) = let open Lwt_result_syntax in - let*! () = lwt_debug "Bootstrap OK@." in + let*! () = lwt_log_info "Bootstrap OK@." in let* () = Node.sync node in let rec loop n msg = if n <= 0 then return_unit @@ -276,10 +276,10 @@ module Simple = struct match msg with | [] -> return_unit | ref_msg :: next -> - let*! () = lwt_debug "Wait broadcaster.@." in + let*! () = lwt_log_info "Wait broadcaster.@." in let* () = Node.sync node in let* _msgs = read_all node.pool ref_msg in - let*! () = lwt_debug "Read message.@." in + let*! () = lwt_log_info "Read message.@." in let* () = Node.sync node in loop (n - 1) (if no_check then next @ [ref_msg] else next) in @@ -288,7 +288,7 @@ module Simple = struct let run points = (* Messages are precomputed for every iteration and shared between processes to allow checking their content *) - debug "Running broadcast test on %d points.@." (List.length points) ; + log_notice "Running broadcast test on %d points.@." (List.length points) ; let msgs = message () in Node.detach_nodes (fun i -> if i = 0 then broadcaster msgs else node msgs) @@ -315,7 +315,7 @@ let wrap addr n f = aux n f) let main () = - let addr = Node.default_ipv6_addr in + let addr = Ipaddr.V6.of_string_exn "::ffff:127.0.0.1" in Lwt_main.run @@ Alcotest_lwt.run "tezos-p2p-broadcast" diff --git a/src/lib_p2p/test/test_p2p_buffer_reader.ml b/src/lib_p2p/test/test_p2p_buffer_reader.ml index 02602ccd429a..791c204101d2 100644 --- a/src/lib_p2p/test/test_p2p_buffer_reader.ml +++ b/src/lib_p2p/test/test_p2p_buffer_reader.ml @@ -27,7 +27,7 @@ (** Testing ------- Component: P2P - Invocation: dune exec src/lib_p2p/test/main.exe + Invocation: dune build @src/lib_p2p/test/runtest_p2p_buffer_reader Subject: Tests [P2p_buffer_reader] *) diff --git a/src/lib_p2p/test/test_p2p_connect_handler.ml b/src/lib_p2p/test/test_p2p_connect_handler.ml index fc1ea95d0a23..bdb0c9018a97 100644 --- a/src/lib_p2p/test/test_p2p_connect_handler.ml +++ b/src/lib_p2p/test/test_p2p_connect_handler.ml @@ -26,7 +26,7 @@ (** Testing ------- Component: P2P - Invocation: dune exec src/lib_p2p/test/main.exe + Invocation: dune build @src/lib_p2p/test/runtest_p2p_connect_handler Subject: Test that P2p_connect_handler is well-behaved *) diff --git a/src/lib_p2p/test/test_p2p_io_scheduler.ml b/src/lib_p2p/test/test_p2p_io_scheduler.ml index 2a5a929b2638..30277f19de3d 100644 --- a/src/lib_p2p/test/test_p2p_io_scheduler.ml +++ b/src/lib_p2p/test/test_p2p_io_scheduler.ml @@ -27,7 +27,7 @@ (** Testing ------- Component: P2P - Invocation: dune exec src/lib_p2p/test/main.exe + Invocation: dune build @src/lib_p2p/test/runtest_p2p_io_scheduler_ipv4 Dependencies: src/lib_p2p/test/process.ml Subject: On I/O scheduling of client-server connections. *) @@ -124,10 +124,10 @@ let server ?(display_client_stat = true) ?max_download_speed ?read_queue_size () in Moving_average.on_update (P2p_io_scheduler.ma_state sched) (fun () -> - debug "Stat: %a" P2p_stat.pp (P2p_io_scheduler.global_stat sched) ; + log_notice "Stat: %a" P2p_stat.pp (P2p_io_scheduler.global_stat sched) ; if display_client_stat then P2p_io_scheduler.iter_connection sched (fun conn -> - debug + log_notice " client(%d) %a" (P2p_io_scheduler.id conn) P2p_stat.pp @@ -139,7 +139,7 @@ let server ?(display_client_stat = true) ?max_download_speed ?read_queue_size let* r = List.iter_ep P2p_io_scheduler.close conns in match r with | Ok () -> - debug "OK %a" P2p_stat.pp (P2p_io_scheduler.global_stat sched) ; + log_notice "OK %a" P2p_stat.pp (P2p_io_scheduler.global_stat sched) ; return_ok () | Error _ -> Lwt.fail Alcotest.Test_error @@ -188,7 +188,7 @@ let client ?max_upload_speed ?write_queue_size addr port time _n = | Error err -> Lwt.fail (Error err) | Ok () -> let stat = P2p_io_scheduler.stat conn in - let* () = lwt_debug "Client OK %a" P2p_stat.pp stat in + let* () = lwt_log_notice "Client OK %a" P2p_stat.pp stat in return_ok () (** Listens to address [addr] on port [port] to open a socket [main_socket]. @@ -251,7 +251,7 @@ let wrap n f = Format.kasprintf Stdlib.failwith "%a" pp_print_trace error) let () = - let addr = Node.default_ipv6_addr in + let addr = Ipaddr.V6.of_string_exn "::ffff:127.0.0.1" in let port = Some (Tezt_tezos.Port.fresh ()) in let max_download_speed = 1048576 in let max_upload_speed = 262144 in diff --git a/src/lib_p2p/test/test_p2p_maintenance.ml b/src/lib_p2p/test/test_p2p_maintenance.ml index 20e2719d747f..0dbe587681ec 100644 --- a/src/lib_p2p/test/test_p2p_maintenance.ml +++ b/src/lib_p2p/test/test_p2p_maintenance.ml @@ -26,7 +26,7 @@ (* Testing ------- Component: lib_p2p - Invocation: dune exec src/lib_p2p/test/main.exe + Invocation: dune exec src/lib_p2p/test/test_p2p_maintenance.exe Subject: Check maintenance mechanism. *) @@ -527,7 +527,7 @@ let main () = let () = Lwt_main.run (Tezos_base_unix.Internal_event_unix.init ~lwt_log_sink ()) in - let addr = Node.default_ipv6_addr in + let addr = Ipaddr.V6.of_string_exn "::ffff:127.0.0.1" in Lwt_main.run @@ Alcotest_lwt.run "tezos-p2p" diff --git a/src/lib_p2p/test/test_p2p_node.ml b/src/lib_p2p/test/test_p2p_node.ml index cde732282f27..a239d24a379a 100644 --- a/src/lib_p2p/test/test_p2p_node.ml +++ b/src/lib_p2p/test/test_p2p_node.ml @@ -26,7 +26,7 @@ (* Testing ------- Component: lib_p2p (test lib) - Invocation: dune exec src/lib_p2p/test/main.exe + Invocation: dune exec src/lib_p2p/test/test_p2p_node.exe Subject: Check p2p test framework. *) module Event = struct @@ -104,7 +104,7 @@ let main () = in Lwt_main.run (Tezos_base_unix.Internal_event_unix.init ~lwt_log_sink ()) in - let addr = Node.default_ipv6_addr in + let addr = Ipaddr.V6.of_string_exn "::ffff:127.0.0.1" in Lwt_main.run @@ Alcotest_lwt.run "tezos-p2p" diff --git a/src/lib_p2p/test/test_p2p_peerset.ml b/src/lib_p2p/test/test_p2p_peerset.ml index 622a6f9b164c..01648efd012f 100644 --- a/src/lib_p2p/test/test_p2p_peerset.ml +++ b/src/lib_p2p/test/test_p2p_peerset.ml @@ -26,7 +26,7 @@ (** Testing ------- Component: P2P - Invocation: dune exec src/lib_p2p/test/main.exe + Invocation: dune build @src/lib_p2p/test/runtest_p2p_peerset Subject: On banning peers and usage of Access Control Lists (ACL) using FIFO caches filled with peers' ids. *) diff --git a/src/lib_p2p/test/test_p2p_pool.ml b/src/lib_p2p/test/test_p2p_pool.ml index 5b7afb253f19..e9234a9395ed 100644 --- a/src/lib_p2p/test/test_p2p_pool.ml +++ b/src/lib_p2p/test/test_p2p_pool.ml @@ -27,7 +27,7 @@ (** Testing ------- Component: P2P - Invocation: dune exec src/lib_p2p/test/main.exe + Invocation: dune build @src/lib_p2p/test/runtest_p2p_pool Dependencies: src/lib_p2p/test/process.ml Subject: Testing of the Pool Each test launches nodes in separate process, each node @@ -46,7 +46,7 @@ type error += Connect | Write | Read module Simple = struct let rec connect ~timeout connect_handler pool point = let open Lwt_syntax in - let* () = lwt_debug "Connect to %a" P2p_point.Id.pp point in + let* () = lwt_log_info "Connect to %a" P2p_point.Id.pp point in let* r = P2p_connect_handler.connect connect_handler point ~timeout in match r with | Error (Tezos_p2p_services.P2p_errors.Connected :: _) -> ( @@ -61,7 +61,7 @@ module Simple = struct | Timeout | Tezos_p2p_services.P2p_errors.Rejected _ ) as head_err) :: _) -> let* () = - lwt_debug + lwt_log_info "Connection to %a failed (%a)@." P2p_point.Id.pp point @@ -126,16 +126,16 @@ module Simple = struct node.pool node.points in - let*! () = lwt_debug "Bootstrap OK@." in + let*! () = lwt_log_info "Bootstrap OK@." in let* () = Node.sync node in let* () = write_all conns Node.Ping in - let*! () = lwt_debug "Sent all messages.@." in + let*! () = lwt_log_info "Sent all messages.@." in let* () = Node.sync node in let* () = read_all conns in - let*! () = lwt_debug "Read all messages.@." in + let*! () = lwt_log_info "Read all messages.@." in let* () = Node.sync node in let*! () = close_all conns in - let*! () = lwt_debug "All connections successfully closed.@." in + let*! () = lwt_log_info "All connections successfully closed.@." in return_unit let run points = Node.detach_nodes (fun _ -> node) points @@ -164,7 +164,7 @@ module Random_connections = struct let*! () = P2p_conn.disconnect conn in let*! () = decr rem ; - if !rem mod total = 0 then lwt_debug "Remaining: %d.@." (!rem / total) + if !rem mod total = 0 then lwt_log_info "Remaining: %d.@." (!rem / total) else Lwt.return_unit in if n > 1 then connect_random connect_handler pool total rem point (pred n) @@ -179,11 +179,11 @@ module Random_connections = struct let node repeat (node : Node.t) = let open Lwt_result_syntax in - let*! () = lwt_debug "Begin random connections.@." in + let*! () = lwt_log_info "Begin random connections.@." in let* () = connect_random_all node.connect_handler node.pool node.points repeat in - let*! () = lwt_debug "Random connections OK.@." in + let*! () = lwt_log_info "Random connections OK.@." in return_unit let run points repeat = Node.detach_nodes (fun _ -> node repeat) points @@ -203,7 +203,7 @@ module Garbled = struct true | Ok _ -> false | Error err -> - debug "Unexpected error: %a@." pp_print_trace err ; + log_info "Unexpected error: %a@." pp_print_trace err ; false let write_bad_all conns = @@ -257,7 +257,7 @@ module Overcrowded = struct let rec connect ?iter_count ~timeout connect_handler pool point = let open Lwt_syntax in let* () = - lwt_debug + lwt_log_info "Connect%a to %a@." (fun ppf iter_count -> Option.iter (Format.fprintf ppf " to peer %d") iter_count) @@ -279,7 +279,7 @@ module Overcrowded = struct | Timeout | Tezos_p2p_services.P2p_errors.Rejected _ ) as err); ] -> let* () = - lwt_debug + lwt_log_info "Connection to%a %a failed (%a)@." (fun ppf iter_count -> Option.iter (Format.fprintf ppf " peer %d") iter_count) @@ -341,7 +341,7 @@ module Overcrowded = struct match r with | Ok conn -> let*! () = - lwt_debug + lwt_log_info "Not good: connection accepted while it should be rejected (local: \ %d, remote: %d).@." port @@ -360,7 +360,7 @@ module Overcrowded = struct ] as err -> if legacy then let*! () = - lwt_debug + lwt_log_info "Good: client is rejected without point list (local: %d, remote: \ %d)@." port @@ -369,7 +369,7 @@ module Overcrowded = struct return_unit else let*! () = - lwt_debug + lwt_log_info "Not good: client is rejected without point list (local: %d, \ remote: %d)@." port @@ -382,7 +382,7 @@ module Overcrowded = struct {alternative_points = Some alternative_points; _}; ] -> let*! () = - lwt_debug + lwt_log_info "Good: client is rejected with point list (local: %d, remote: %d) \ @[%a@]@." port @@ -412,11 +412,11 @@ module Overcrowded = struct let unknowns, _known = client_knowledge pool all_points in let advert_succeed = unknowns = [] in if legacy || advert_succeed then - debug + log_info "Good: Advertisement%s worked as intended.@." (if legacy then " legacy" else "") else - debug + log_info "@[Not Good: advertisement failure. legacy %b. unknowns : @[%a@]\n\ \t knowns : @[%a@].@." legacy @@ -460,7 +460,7 @@ module Overcrowded = struct let* () = client_check node.pool node.points legacy in let* () = Node.sync node in (* sync 4 *) - let*! () = lwt_debug "client closing.@." in + let*! () = lwt_log_info "client closing.@." in return_unit (** Code of the target that should be overcrowded by all the clients. *) @@ -488,7 +488,7 @@ module Overcrowded = struct let _pool_log = Lwt_stream.iter (debug "p2p event %a" P2p_connection.P2p_event.pp) log in - let*! () = lwt_debug "Target waiting@." in + let*! () = lwt_log_info "Target waiting@." in let* () = Node.sync node in (* sync 2 *) let* () = Node.sync node in @@ -496,7 +496,7 @@ module Overcrowded = struct let* () = Node.sync node in (* sync 4 *) Lwt_watcher.shutdown stopper ; - let*! () = lwt_debug "Target closing.@." in + let*! () = lwt_log_info "Target closing.@." in return_unit let node i = if i = 0 then target else client false @@ -569,7 +569,7 @@ module No_common_network = struct let rec connect ?iter_count ~timeout connect_handler pool point = let open Lwt_syntax in let* () = - lwt_debug + lwt_log_info "Connect%a to @[%a@]@." (fun ppf iter_count -> Option.iter (Format.fprintf ppf " to peer %d") iter_count) @@ -591,7 +591,7 @@ module No_common_network = struct | Timeout | Tezos_p2p_services.P2p_errors.Rejected _ ) as err); ] -> let* () = - lwt_debug + lwt_log_info "Connection to%a %a failed (%a)@." (fun ppf iter_count -> Option.iter (Format.fprintf ppf " peer %d") iter_count) @@ -645,7 +645,7 @@ module No_common_network = struct match r with | Ok conn -> let*! () = - lwt_debug + lwt_log_info "Not good: connection accepted while it should be rejected.@." in let*! () = P2p_conn.disconnect conn in @@ -654,7 +654,7 @@ module No_common_network = struct [Tezos_p2p_services.P2p_errors.Rejected_no_common_protocol {announced}] -> let*! () = - lwt_debug + lwt_log_info "Good: Connection cannot be established,no common network with \ @[%a@].@." Network_version.pp @@ -674,16 +674,16 @@ module No_common_network = struct in let* () = Node.sync node in (* sync 2 *) - let*! () = lwt_debug "client closing.@." in + let*! () = lwt_log_info "client closing.@." in return_unit (** Code of the target that should be overcrowded by all the clients. *) let target (node : Node.t) = let open Lwt_result_syntax in - let*! () = lwt_debug "Target waiting.@." in + let*! () = lwt_log_info "Target waiting.@." in let* () = Node.sync node in (* sync 2 *) - let*! () = lwt_debug "Target closing.@." in + let*! () = lwt_log_info "Target closing.@." in return_unit let node i = if i = 0 then target else client @@ -728,9 +728,11 @@ let init_logs = let points = ref [] -let wrap ?port ?(clients = 10) n f = +let wrap ?addr ?port ?(clients = 10) n f = let gen_points addr = points := Node.gen_points ?port clients addr in - let addr = Node.default_ipv6_addr in + let addr = + Option.value ~default:(Ipaddr.V6.of_string_exn "::ffff:127.0.0.1") addr + in gen_points addr ; Alcotest_lwt.test_case n `Quick (fun _ () -> let open Lwt_syntax in diff --git a/src/lib_p2p/test/test_p2p_socket.ml b/src/lib_p2p/test/test_p2p_socket.ml index 65b20bbfa63f..d91258bcce1d 100644 --- a/src/lib_p2p/test/test_p2p_socket.ml +++ b/src/lib_p2p/test/test_p2p_socket.ml @@ -27,7 +27,7 @@ (** Testing ------- Component: P2P - Invocation: dune exec src/lib_p2p/test/main.exe + Invocation: dune build @src/lib_p2p/test/runtest_p2p_socket_ipv4 Dependencies: src/lib_p2p/test/process.ml Subject: Sockets and client-server communications. *) @@ -531,7 +531,7 @@ let wrap n f = Format.kasprintf Stdlib.failwith "%a" pp_print_trace error) let main () = - P2p_test_utils.addr := Node.default_ipv6_addr ; + P2p_test_utils.addr := Ipaddr.V6.of_string_exn "::ffff:127.0.0.1" ; Lwt_main.run @@ Alcotest_lwt.run "tezos-p2p" diff --git a/tezt/lib_alcotezt/alcotest.ml b/tezt/lib_alcotezt/alcotest.ml index 2d6df52874f2..17654731c758 100644 --- a/tezt/lib_alcotezt/alcotest.ml +++ b/tezt/lib_alcotezt/alcotest.ml @@ -55,18 +55,7 @@ let run library_name tests = body ()) ; Base.unit -module type TESTABLE = sig - (** The type to test. *) - type t - - (** A way to pretty-print the value. *) - val pp : Format.formatter -> t -> unit - - (** Test for equality between two values. *) - val equal : t -> t -> bool -end - -type 'a testable = (module TESTABLE with type t = 'a) +type 'a testable = (module Tezt_core.Check.EQUALABLE with type t = 'a) let testable (type a) (pp : Format.formatter -> a -> return) (eq : a -> a -> bool) : a testable = diff --git a/tezt/lib_alcotezt/alcotest.mli b/tezt/lib_alcotezt/alcotest.mli index 7b4efb682156..d58207d50e7e 100644 --- a/tezt/lib_alcotezt/alcotest.mli +++ b/tezt/lib_alcotezt/alcotest.mli @@ -71,19 +71,8 @@ type 'a test = string * 'a test_case list The name of the test suite is used as the filename for the Tezt test. *) val run : string -> unit test list -> return -module type TESTABLE = sig - (** The type to test. *) - type t - - (** A way to pretty-print the value. *) - val pp : Format.formatter -> t -> unit - - (** Test for equality between two values. *) - val equal : t -> t -> bool -end - (** Values that can be tested with {!check}. *) -type 'a testable = (module TESTABLE with type t = 'a) +type 'a testable = (module Tezt_core.Check.EQUALABLE with type t = 'a) (** [testable pp eq] is a new {!type-testable} with the pretty-printer [pp] and equality [eq]. *) @@ -93,8 +82,7 @@ val testable : (** [pp t] is [t]'s pretty-printer. *) val pp : 'a testable -> Format.formatter -> 'a -> return -(** [of_pp pp] tests values which can be printed using [pp] and compared using - {!Stdlib.compare} *) +(** [of_pp pp] tests values which can be printed using [pp] and compared using {!Stdlib.compare} *) val of_pp : (Format.formatter -> 'a -> return) -> 'a testable (** [equal t] is [t]'s equality. *) diff --git a/tezt/tests/dune b/tezt/tests/dune index 1fdb194fd37b..b95109ecf5f7 100644 --- a/tezt/tests/dune +++ b/tezt/tests/dune @@ -73,7 +73,6 @@ src_lib_protocol_environment_test_shell_context_tezt_lib src_lib_protocol_environment_test_tezt_lib src_lib_p2p_tezt_tezt_lib - src_lib_p2p_test_tezt_lib src_lib_mockup_test_tezt_lib src_lib_lwt_result_stdlib_test_tezt_lib src_lib_lazy_containers_test_tezt_lib -- GitLab