From f961f0e74290d473fd5a4854ccbff24520a8d9b0 Mon Sep 17 00:00:00 2001 From: Pietro Abate Date: Fri, 17 Mar 2023 10:26:15 +0100 Subject: [PATCH 1/2] p2p: reduce verbosity of all p2p unit tests --- src/lib_p2p/test/common/process.ml | 8 ++-- src/lib_p2p/test/test_p2p_broadcast.ml | 24 +++++----- src/lib_p2p/test/test_p2p_io_scheduler.ml | 8 ++-- src/lib_p2p/test/test_p2p_pool.ml | 56 +++++++++++------------ 4 files changed, 47 insertions(+), 49 deletions(-) diff --git a/src/lib_p2p/test/common/process.ml b/src/lib_p2p/test/common/process.ml index e3ff33308257..f9c0fd0dda80 100644 --- a/src/lib_p2p/test/common/process.ml +++ b/src/lib_p2p/test/common/process.ml @@ -35,9 +35,7 @@ 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 -let lwt_log_notice fmt = log_f ~level:Lwt_log.Notice fmt - -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_error fmt = log_f ~level:Lwt_log.Error fmt @@ -241,7 +239,7 @@ let detach ?(prefix = "") ?canceler ?input_encoding ?output_encoding ~close_mode:`Keep ~channel:Lwt_io.stderr () ; - let* () = lwt_log_notice "PID: %d" (Unix.getpid ()) in + let* () = lwt_log_debug "PID: %d" (Unix.getpid ()) in handle_result ~value_encoding ~flags @@ -442,7 +440,7 @@ let wait_all_results (processes : ('a, 'b, 'c) t list) = let* o = loop terminations in match o with | None -> ( - let* () = lwt_log_info "All done!" in + let* () = lwt_log_debug "All done!" in let* terminated = all terminations in match List.partition_result terminated with | _, _ :: _ -> assert false diff --git a/src/lib_p2p/test/test_p2p_broadcast.ml b/src/lib_p2p/test/test_p2p_broadcast.ml index d6e26e7f54a6..f24c814891cd 100644 --- a/src/lib_p2p/test/test_p2p_broadcast.ml +++ b/src/lib_p2p/test/test_p2p_broadcast.ml @@ -92,7 +92,7 @@ module Simple = struct let rec connect ~timeout connect_handler pool point = let open Lwt_syntax in - let* () = lwt_log_info "Connect to %a" P2p_point.Id.pp point in + let* () = lwt_debug "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_log_info + lwt_debug "Connection to %a failed (%a)@." P2p_point.Id.pp point @@ -219,7 +219,7 @@ module Simple = struct node.pool node.points in - let*! () = lwt_log_info "Bootstrap OK@." in + let*! () = lwt_debug "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_log_info "Broadcast message in %a.@." Ptime.Span.pp span + lwt_debug "Broadcast message in %a.@." Ptime.Span.pp span in let* () = Node.sync node in - let*! () = lwt_log_info "Wait others.@." in + let*! () = lwt_debug "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_log_notice + lwt_debug "%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_log_info "All connections successfully closed.@." in - let*! () = lwt_log_notice "type; max; min; avg; median; std_dev" in + let*! () = lwt_debug "All connections successfully closed.@." in + let*! () = lwt_debug "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_log_info "Bootstrap OK@." in + let*! () = lwt_debug "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_log_info "Wait broadcaster.@." in + let*! () = lwt_debug "Wait broadcaster.@." in let* () = Node.sync node in let* _msgs = read_all node.pool ref_msg in - let*! () = lwt_log_info "Read message.@." in + let*! () = lwt_debug "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 *) - log_notice "Running broadcast test on %d points.@." (List.length points) ; + debug "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) diff --git a/src/lib_p2p/test/test_p2p_io_scheduler.ml b/src/lib_p2p/test/test_p2p_io_scheduler.ml index 30277f19de3d..a4105c8cd372 100644 --- a/src/lib_p2p/test/test_p2p_io_scheduler.ml +++ b/src/lib_p2p/test/test_p2p_io_scheduler.ml @@ -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 () -> - log_notice "Stat: %a" P2p_stat.pp (P2p_io_scheduler.global_stat sched) ; + debug "Stat: %a" P2p_stat.pp (P2p_io_scheduler.global_stat sched) ; if display_client_stat then P2p_io_scheduler.iter_connection sched (fun conn -> - log_notice + debug " 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 () -> - log_notice "OK %a" P2p_stat.pp (P2p_io_scheduler.global_stat sched) ; + debug "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_log_notice "Client OK %a" P2p_stat.pp stat in + let* () = lwt_debug "Client OK %a" P2p_stat.pp stat in return_ok () (** Listens to address [addr] on port [port] to open a socket [main_socket]. diff --git a/src/lib_p2p/test/test_p2p_pool.ml b/src/lib_p2p/test/test_p2p_pool.ml index e9234a9395ed..0ed47c4db872 100644 --- a/src/lib_p2p/test/test_p2p_pool.ml +++ b/src/lib_p2p/test/test_p2p_pool.ml @@ -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_log_info "Connect to %a" P2p_point.Id.pp point in + let* () = lwt_debug "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_log_info + lwt_debug "Connection to %a failed (%a)@." P2p_point.Id.pp point @@ -126,16 +126,16 @@ module Simple = struct node.pool node.points in - let*! () = lwt_log_info "Bootstrap OK@." in + let*! () = lwt_debug "Bootstrap OK@." in let* () = Node.sync node in let* () = write_all conns Node.Ping in - let*! () = lwt_log_info "Sent all messages.@." in + let*! () = lwt_debug "Sent all messages.@." in let* () = Node.sync node in let* () = read_all conns in - let*! () = lwt_log_info "Read all messages.@." in + let*! () = lwt_debug "Read all messages.@." in let* () = Node.sync node in let*! () = close_all conns in - let*! () = lwt_log_info "All connections successfully closed.@." in + let*! () = lwt_debug "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_log_info "Remaining: %d.@." (!rem / total) + if !rem mod total = 0 then lwt_debug "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_log_info "Begin random connections.@." in + let*! () = lwt_debug "Begin random connections.@." in let* () = connect_random_all node.connect_handler node.pool node.points repeat in - let*! () = lwt_log_info "Random connections OK.@." in + let*! () = lwt_debug "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 -> - log_info "Unexpected error: %a@." pp_print_trace err ; + debug "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_log_info + lwt_debug "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_log_info + lwt_debug "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_log_info + lwt_debug "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_log_info + lwt_debug "Good: client is rejected without point list (local: %d, remote: \ %d)@." port @@ -369,7 +369,7 @@ module Overcrowded = struct return_unit else let*! () = - lwt_log_info + lwt_debug "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_log_info + lwt_debug "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 - log_info + debug "Good: Advertisement%s worked as intended.@." (if legacy then " legacy" else "") else - log_info + debug "@[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_log_info "client closing.@." in + let*! () = lwt_debug "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_log_info "Target waiting@." in + let*! () = lwt_debug "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_log_info "Target closing.@." in + let*! () = lwt_debug "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_log_info + lwt_debug "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_log_info + lwt_debug "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_log_info + lwt_debug "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_log_info + lwt_debug "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_log_info "client closing.@." in + let*! () = lwt_debug "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_log_info "Target waiting.@." in + let*! () = lwt_debug "Target waiting.@." in let* () = Node.sync node in (* sync 2 *) - let*! () = lwt_log_info "Target closing.@." in + let*! () = lwt_debug "Target closing.@." in return_unit let node i = if i = 0 then target else client -- GitLab From ef3beb90c3afa32a6d27c736e7729876be5eabb6 Mon Sep 17 00:00:00 2001 From: Pietro Abate Date: Wed, 22 Mar 2023 11:50:19 +0100 Subject: [PATCH 2/2] p2p: use ::1 as ipv6 localhost --- src/lib_p2p/test/common/node.ml | 2 ++ src/lib_p2p/test/common/node.mli | 2 ++ src/lib_p2p/test/common/p2p_test_utils.ml | 10 +++++----- src/lib_p2p/test/common/p2p_test_utils.mli | 3 +-- src/lib_p2p/test/test_p2p_broadcast.ml | 2 +- src/lib_p2p/test/test_p2p_io_scheduler.ml | 2 +- src/lib_p2p/test/test_p2p_logging.ml | 14 +++++++------- src/lib_p2p/test/test_p2p_maintenance.ml | 2 +- src/lib_p2p/test/test_p2p_node.ml | 2 +- src/lib_p2p/test/test_p2p_pool.ml | 6 ++---- src/lib_p2p/test/test_p2p_socket.ml | 22 +++++++++++----------- src/lib_p2p/tezt/test_p2p_socket.ml | 6 +----- 12 files changed, 35 insertions(+), 38 deletions(-) diff --git a/src/lib_p2p/test/common/node.ml b/src/lib_p2p/test/common/node.ml index 1a5f568d83e5..476619f1ceed 100644 --- a/src/lib_p2p/test/common/node.ml +++ b/src/lib_p2p/test/common/node.ml @@ -294,6 +294,8 @@ 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 48e175051003..a5f33df32451 100644 --- a/src/lib_p2p/test/common/node.mli +++ b/src/lib_p2p/test/common/node.mli @@ -56,6 +56,8 @@ 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/p2p_test_utils.ml b/src/lib_p2p/test/common/p2p_test_utils.ml index b71fc1b53e13..75c2f74a5e4f 100644 --- a/src/lib_p2p/test/common/p2p_test_utils.ml +++ b/src/lib_p2p/test/common/p2p_test_utils.ml @@ -117,8 +117,6 @@ let id1 = P2p_identity.generate proof_of_work_target let id2 = P2p_identity.generate proof_of_work_target -let addr = ref Ipaddr.V6.localhost - let version = { Network_version.chain_name = @@ -168,7 +166,9 @@ let sync_nodes nodes = | Ok () | Error (Exn End_of_file :: _) -> return_unit | Error _ as err -> Lwt.return err -let run_nodes ?port client server = +(* addr here is localhost as we run different nodes + on the same addr but different ports *) +let run_nodes ~addr ?port client server = let open Lwt_result_syntax in let p = match port with @@ -179,7 +179,7 @@ let run_nodes ?port client server = glob_port := Some (p + 1) ; Some p in - let*! main_socket, p = listen ?port:p !addr in + let*! main_socket, p = listen ?port:p addr in let* server_node = Process.detach ~prefix:"server: " (fun channel -> let sched = P2p_io_scheduler.create ~read_buffer_size:(1 lsl 12) () in @@ -198,7 +198,7 @@ let run_nodes ?port client server = | Ok () -> Lwt.return_unit in let sched = P2p_io_scheduler.create ~read_buffer_size:(1 lsl 12) () in - let* () = client channel sched !addr p in + let* () = client channel sched addr p in let*! () = P2p_io_scheduler.shutdown sched in return_unit) in diff --git a/src/lib_p2p/test/common/p2p_test_utils.mli b/src/lib_p2p/test/common/p2p_test_utils.mli index e1a685e44ef4..099ac700315e 100644 --- a/src/lib_p2p/test/common/p2p_test_utils.mli +++ b/src/lib_p2p/test/common/p2p_test_utils.mli @@ -70,8 +70,6 @@ val connect_all : function waits until the connections are effectively closed. *) val close_active_conns : ('a, 'b, 'c) Tezos_p2p.P2p_pool.t -> unit Lwt.t -val addr : Ipaddr.V6.t ref - val canceler : Lwt_canceler.t val proof_of_work_target : Tezos_crypto.Crypto_box.pow_target @@ -81,6 +79,7 @@ val id1 : P2p_identity.t Lwt.t val id2 : P2p_identity.t Lwt.t val run_nodes : + addr:P2p_addr.t -> ?port:int -> ((unit, unit) Process.Channel.t -> P2p_io_scheduler.t -> diff --git a/src/lib_p2p/test/test_p2p_broadcast.ml b/src/lib_p2p/test/test_p2p_broadcast.ml index f24c814891cd..4a9d8d2199e4 100644 --- a/src/lib_p2p/test/test_p2p_broadcast.ml +++ b/src/lib_p2p/test/test_p2p_broadcast.ml @@ -315,7 +315,7 @@ let wrap addr n f = aux n f) let main () = - let addr = Ipaddr.V6.of_string_exn "::ffff:127.0.0.1" in + let addr = Node.default_ipv6_addr in Lwt_main.run @@ Alcotest_lwt.run "tezos-p2p-broadcast" diff --git a/src/lib_p2p/test/test_p2p_io_scheduler.ml b/src/lib_p2p/test/test_p2p_io_scheduler.ml index a4105c8cd372..450fa43d0faf 100644 --- a/src/lib_p2p/test/test_p2p_io_scheduler.ml +++ b/src/lib_p2p/test/test_p2p_io_scheduler.ml @@ -251,7 +251,7 @@ let wrap n f = Format.kasprintf Stdlib.failwith "%a" pp_print_trace error) let () = - let addr = Ipaddr.V6.of_string_exn "::ffff:127.0.0.1" in + let addr = Node.default_ipv6_addr 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_logging.ml b/src/lib_p2p/test/test_p2p_logging.ml index a877feca0960..e56eb3822636 100644 --- a/src/lib_p2p/test/test_p2p_logging.ml +++ b/src/lib_p2p/test/test_p2p_logging.ml @@ -1,7 +1,7 @@ module type TEST = sig val name : string - val run : unit -> unit tzresult Lwt.t + val run : addr:P2p_addr.t -> unit -> unit tzresult Lwt.t end let canceler = Lwt_canceler.create () (* unused *) @@ -67,7 +67,7 @@ module Authentication = struct close_event ; return_unit - let run _dir = run_nodes client server + let run ~addr () = run_nodes ~addr client server end module Nack = struct @@ -104,7 +104,7 @@ module Nack = struct let*! _conn = P2p_socket.accept ~canceler auth_fd Data_encoding.bytes in sync ch - let run _ = run_nodes client server + let run ~addr () = run_nodes ~addr client server end module Read_and_write = struct @@ -187,7 +187,7 @@ module Read_and_write = struct message_event ; return_unit - let run _dir = run_nodes client server + let run ~addr () = run_nodes ~addr client server end module P2p_net = struct @@ -285,7 +285,7 @@ module P2p_net = struct section = Some (Some (Internal_event.Section.make_sanitized ["p2p"])); } - let run () = + let run ~addr:_ () = let open Lwt_result_syntax in let*! identity = P2p_test_utils.id1 in let* net = @@ -327,11 +327,12 @@ end let lwt_log_sink = Lwt_log_sink_unix.create_cfg ~rules:"* -> debug" () let testcase (module T : TEST) = + let addr = Node.default_ipv6_addr in Alcotest_lwt.test_case T.name `Quick (fun _switch () -> let open Lwt_syntax in let* () = Tezos_base_unix.Internal_event_unix.init ~lwt_log_sink () in Tztest.with_empty_mock_sink (fun () -> - let* r = T.run () in + let* r = T.run ~addr () in match r with | Ok () -> return_unit | Error error -> @@ -340,7 +341,6 @@ let testcase (module T : TEST) = let () = Lwt_main.run @@ Alcotest_lwt.run - ~argv:[|""|] "tezos-p2p" [ ( "p2p-logging", diff --git a/src/lib_p2p/test/test_p2p_maintenance.ml b/src/lib_p2p/test/test_p2p_maintenance.ml index 0dbe587681ec..7e635b8e63eb 100644 --- a/src/lib_p2p/test/test_p2p_maintenance.ml +++ b/src/lib_p2p/test/test_p2p_maintenance.ml @@ -527,7 +527,7 @@ let main () = let () = Lwt_main.run (Tezos_base_unix.Internal_event_unix.init ~lwt_log_sink ()) in - let addr = Ipaddr.V6.of_string_exn "::ffff:127.0.0.1" in + let addr = Node.default_ipv6_addr 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 a239d24a379a..b39763bae609 100644 --- a/src/lib_p2p/test/test_p2p_node.ml +++ b/src/lib_p2p/test/test_p2p_node.ml @@ -104,7 +104,7 @@ let main () = in Lwt_main.run (Tezos_base_unix.Internal_event_unix.init ~lwt_log_sink ()) in - let addr = Ipaddr.V6.of_string_exn "::ffff:127.0.0.1" in + let addr = Node.default_ipv6_addr in Lwt_main.run @@ Alcotest_lwt.run "tezos-p2p" diff --git a/src/lib_p2p/test/test_p2p_pool.ml b/src/lib_p2p/test/test_p2p_pool.ml index 0ed47c4db872..d4d5fe5d909f 100644 --- a/src/lib_p2p/test/test_p2p_pool.ml +++ b/src/lib_p2p/test/test_p2p_pool.ml @@ -728,11 +728,9 @@ let init_logs = let points = ref [] -let wrap ?addr ?port ?(clients = 10) n f = +let wrap ?port ?(clients = 10) n f = let gen_points addr = points := Node.gen_points ?port clients addr in - let addr = - Option.value ~default:(Ipaddr.V6.of_string_exn "::ffff:127.0.0.1") addr - in + let addr = Node.default_ipv6_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 b73cd7839827..e201507b6482 100644 --- a/src/lib_p2p/test/test_p2p_socket.ml +++ b/src/lib_p2p/test/test_p2p_socket.ml @@ -212,7 +212,7 @@ module Pow_check = struct let* conn = connect sched addr port id in tzassert (is_connection_closed conn) __POS__ - let run _dir = run_nodes client server + let run addr _dir = run_nodes ~addr client server end (** Spawns a client and a server. After the client getting connected to @@ -251,7 +251,7 @@ module Low_level = struct let* () = P2p_io_scheduler.close fd in return_unit - let run _dir = run_nodes client server + let run addr _dir = run_nodes ~addr client server end (** Spawns a client and a server. A client trying to connect to a @@ -282,7 +282,7 @@ module Nacked = struct let*! () = P2p_socket.nack auth_fd P2p_rejection.No_motive [] in sync ch - let run _dir = run_nodes client server + let run addr _dir = run_nodes ~addr client server end (** Spawns a client and a server. A client tries to connect to a @@ -320,7 +320,7 @@ module Simple_message = struct let*! _stat = P2p_socket.close conn in return_unit - let run _dir = run_nodes client server + let run addr _dir = run_nodes ~addr client server end (** Spawns a client and a server. A client tries to connect to a @@ -362,7 +362,7 @@ module Chunked_message = struct let*! _stat = P2p_socket.close conn in return_unit - let run _dir = run_nodes client server + let run addr _dir = run_nodes ~addr client server end (** Two messages of size 131072 bytes are randomly generated. After @@ -404,7 +404,7 @@ module Oversized_message = struct let*! _stat = P2p_socket.close conn in return_unit - let run _dir = run_nodes client server + let run addr _dir = run_nodes ~addr client server end (** After then successful connection of a client to a server, the client @@ -433,7 +433,7 @@ module Close_on_read = struct let*! _stat = P2p_socket.close conn in return_unit - let run _dir = run_nodes client server + let run addr _dir = run_nodes ~addr client server end (** After the successful connection of a client to a server, the client @@ -465,7 +465,7 @@ module Close_on_write = struct let*! _stat = P2p_socket.close conn in return_unit - let run _dir = run_nodes client server + let run addr _dir = run_nodes ~addr client server end (** A dummy message is generated into [garbled_msg]. After the @@ -509,7 +509,7 @@ module Garbled_data = struct let*! _stat = P2p_socket.close conn in return_unit - let run _dir = run_nodes client server + let run addr _dir = run_nodes ~addr client server end let init_logs = @@ -521,17 +521,17 @@ let init_logs = lazy (Tezos_base_unix.Internal_event_unix.init ~lwt_log_sink ()) let wrap n f = + let addr = Node.default_ipv6_addr in Alcotest_lwt.test_case n `Quick (fun _ () -> let open Lwt_syntax in let* () = Lazy.force init_logs in - let* r = f () in + let* r = f addr () in match r with | Ok () -> Lwt.return_unit | Error error -> Format.kasprintf Stdlib.failwith "%a" pp_print_trace error) let main () = - 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/src/lib_p2p/tezt/test_p2p_socket.ml b/src/lib_p2p/tezt/test_p2p_socket.ml index 88bfe2971d50..aed23f3285a0 100644 --- a/src/lib_p2p/tezt/test_p2p_socket.ml +++ b/src/lib_p2p/tezt/test_p2p_socket.ml @@ -39,9 +39,6 @@ end) let p2p_peer_id_typ = Check.comparable P2p_peer.Id.pp P2p_peer.Id.compare -let set_addr_to_ipv4_localhost () = - addr := Ipaddr.V6.of_string_exn "::ffff:127.0.0.1" - (** [connect ?target_id ?proof_of_work_target sched addr port] connect and performs [P2p_socket.authenticate] with the given [proof_of_work_target] (also checking that the remote point is the @@ -100,7 +97,7 @@ let nack_test () = sync ch in - let* _ = run_nodes client server in + let* _ = run_nodes ~addr:Node.default_ipv6_addr client server in unit let () = @@ -111,5 +108,4 @@ let () = successful using ipv6 on your machine, this will not work on the CI as ipv6 network interface is disabled on CI's executors. *) - set_addr_to_ipv4_localhost () ; nack_test () -- GitLab