mirror of
https://github.com/c-cube/moonpool.git
synced 2025-12-06 11:15:38 -05:00
echo server tests for moonpool-lwt
This commit is contained in:
parent
004f5fc82b
commit
f68f27a4a4
4 changed files with 131 additions and 3 deletions
|
|
@ -12,3 +12,14 @@
|
||||||
(rule
|
(rule
|
||||||
(alias runtest)
|
(alias runtest)
|
||||||
(action (diff ./output_hash.expected ./output_hash.txt)))
|
(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)))
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ module M = Moonpool
|
||||||
module M_lwt = Moonpool_lwt
|
module M_lwt = Moonpool_lwt
|
||||||
module Trace = Trace_core
|
module Trace = Trace_core
|
||||||
|
|
||||||
|
let spf = Printf.sprintf
|
||||||
let ( let@ ) = ( @@ )
|
let ( let@ ) = ( @@ )
|
||||||
|
|
||||||
let main ~port ~runner ~n ~n_conn () : unit Lwt.t =
|
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 ->
|
M_lwt.TCP_client.with_connect addr @@ fun ic oc ->
|
||||||
let buf = Bytes.create 32 in
|
let buf = Bytes.create 32 in
|
||||||
|
|
||||||
for _j = 1 to 100 do
|
for _j = 1 to 10 do
|
||||||
let _sp =
|
let _sp =
|
||||||
Trace.enter_manual_sub_span ~parent:_sp ~__FILE__ ~__LINE__
|
Trace.enter_manual_sub_span ~parent:_sp ~__FILE__ ~__LINE__
|
||||||
"write.loop"
|
"write.loop"
|
||||||
in
|
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;
|
M_lwt.IO_out.flush oc;
|
||||||
|
|
||||||
(* read back something *)
|
(* 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;
|
Trace.exit_manual_span _sp;
|
||||||
()
|
()
|
||||||
done;
|
done;
|
||||||
|
|
|
||||||
104
test/lwt/output_echo.expected
Normal file
104
test/lwt/output_echo.expected
Normal file
|
|
@ -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
|
||||||
10
test/lwt/run_echo.sh
Executable file
10
test/lwt/run_echo.sh
Executable file
|
|
@ -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
|
||||||
Loading…
Add table
Reference in a new issue