From f68f27a4a4843f49bf1382dd77d8f646ac1f47c7 Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Tue, 20 Feb 2024 18:34:35 -0500 Subject: [PATCH] echo server tests for moonpool-lwt --- test/lwt/dune | 11 ++++ test/lwt/echo_client.ml | 9 ++- test/lwt/output_echo.expected | 104 ++++++++++++++++++++++++++++++++++ test/lwt/run_echo.sh | 10 ++++ 4 files changed, 131 insertions(+), 3 deletions(-) create mode 100644 test/lwt/output_echo.expected create mode 100755 test/lwt/run_echo.sh diff --git a/test/lwt/dune b/test/lwt/dune index e4708887..d04c3edf 100644 --- a/test/lwt/dune +++ b/test/lwt/dune @@ -12,3 +12,14 @@ (rule (alias runtest) (action (diff ./output_hash.expected ./output_hash.txt))) + +(rule + (targets output_echo.txt) + (deps ./echo_server.exe ./echo_client.exe ./run_echo.sh) + (action + (with-stdout-to %{targets} + (run ./run_echo.sh -n 10 --n-conn=2 -j=4)))) + +(rule + (alias runtest) + (action (diff ./output_echo.expected ./output_echo.txt))) diff --git a/test/lwt/echo_client.ml b/test/lwt/echo_client.ml index c4446d1d..731cdd21 100644 --- a/test/lwt/echo_client.ml +++ b/test/lwt/echo_client.ml @@ -2,6 +2,7 @@ module M = Moonpool module M_lwt = Moonpool_lwt module Trace = Trace_core +let spf = Printf.sprintf let ( let@ ) = ( @@ ) let main ~port ~runner ~n ~n_conn () : unit Lwt.t = @@ -26,17 +27,19 @@ let main ~port ~runner ~n ~n_conn () : unit Lwt.t = M_lwt.TCP_client.with_connect addr @@ fun ic oc -> let buf = Bytes.create 32 in - for _j = 1 to 100 do + for _j = 1 to 10 do let _sp = Trace.enter_manual_sub_span ~parent:_sp ~__FILE__ ~__LINE__ "write.loop" in - M_lwt.IO_out.output_string oc "hello"; + let s = spf "hello %d" _j in + M_lwt.IO_out.output_string oc s; M_lwt.IO_out.flush oc; (* read back something *) - M_lwt.IO_in.really_input ic buf 0 (String.length "hello"); + M_lwt.IO_in.really_input ic buf 0 (String.length s); + Printf.printf "read: %s\n%!" (Bytes.sub_string buf 0 (String.length s)); Trace.exit_manual_span _sp; () done; diff --git a/test/lwt/output_echo.expected b/test/lwt/output_echo.expected new file mode 100644 index 00000000..eb4d3048 --- /dev/null +++ b/test/lwt/output_echo.expected @@ -0,0 +1,104 @@ +run echo client -p 1235 -n 10 --n-conn=2 -j=4 +connecting to port 1235 +read: hello 1 +read: hello 1 +listening on port 1235 +read: hello 2 +read: hello 2 +read: hello 3 +read: hello 3 +read: hello 4 +read: hello 4 +read: hello 5 +read: hello 5 +read: hello 6 +read: hello 6 +read: hello 7 +read: hello 7 +read: hello 8 +read: hello 8 +read: hello 9 +read: hello 9 +read: hello 10 +read: hello 10 +read: hello 1 +read: hello 1 +read: hello 2 +read: hello 2 +read: hello 3 +read: hello 3 +read: hello 4 +read: hello 4 +read: hello 5 +read: hello 5 +read: hello 6 +read: hello 6 +read: hello 7 +read: hello 7 +read: hello 8 +read: hello 8 +read: hello 9 +read: hello 9 +read: hello 10 +read: hello 10 +read: hello 1 +read: hello 1 +read: hello 2 +read: hello 2 +read: hello 3 +read: hello 3 +read: hello 4 +read: hello 4 +read: hello 5 +read: hello 5 +read: hello 6 +read: hello 6 +read: hello 7 +read: hello 7 +read: hello 8 +read: hello 8 +read: hello 9 +read: hello 9 +read: hello 10 +read: hello 10 +read: hello 1 +read: hello 1 +read: hello 2 +read: hello 2 +read: hello 3 +read: hello 3 +read: hello 4 +read: hello 4 +read: hello 5 +read: hello 5 +read: hello 6 +read: hello 6 +read: hello 7 +read: hello 7 +read: hello 8 +read: hello 8 +read: hello 9 +read: hello 9 +read: hello 10 +read: hello 10 +read: hello 1 +read: hello 1 +read: hello 2 +read: hello 2 +read: hello 3 +read: hello 3 +read: hello 4 +read: hello 4 +read: hello 5 +read: hello 5 +read: hello 6 +read: hello 6 +read: hello 7 +read: hello 7 +read: hello 8 +read: hello 8 +read: hello 9 +read: hello 9 +read: hello 10 +read: hello 10 +all done diff --git a/test/lwt/run_echo.sh b/test/lwt/run_echo.sh new file mode 100755 index 00000000..91172854 --- /dev/null +++ b/test/lwt/run_echo.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +PORT=1235 +./echo_server.exe -p $PORT & + +echo "run echo client -p $PORT $@" + +./echo_client.exe -p $PORT $@ + +kill %1