Skip to content

Commit

Permalink
Add simple eio send_all/receive_all test
Browse files Browse the repository at this point in the history
  • Loading branch information
ComanderP committed May 9, 2024
1 parent d2d85bd commit c94e954
Showing 1 changed file with 35 additions and 9 deletions.
44 changes: 35 additions & 9 deletions zmq-eio/test/test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ let send env ?(delay = 0.0) s count =
in
fun () -> inner count

let send_all env ?(delay = 0.0) s count =
let rec inner = function
| 0 -> ()
| n ->
Zmq_eio.Socket.send_all s ["test1"; "test2"; "test3"];
sleepf env delay;
inner (n - 1)
in
fun () -> inner count

let recv env ?(delay = 0.0) s count =
let rec inner = function
| 0 -> ()
Expand All @@ -48,6 +58,16 @@ let recv env ?(delay = 0.0) s count =
in
fun () -> inner count

let recv_all env ?(delay = 0.0) s count =
let rec inner = function
| 0 -> ()
| n ->
let _ = Zmq_eio.Socket.recv_all s in
sleepf env delay;
inner (n - 1)
in
fun () -> inner count

(** Test functions *)
let test_setup_teardown ~sw:_ _env _s = ()

Expand All @@ -59,6 +79,12 @@ let test_send_receive ~sw:_ env (_, s1, s2) =
recv env s1 count;
]

let test_send_receive_all ~sw:_ env (_, s1, s2) =
all_ok [
send_all env s2 count;
recv_all env s1 count;
]

let test_msend_mreceive ~sw:_ env (_, s1, s2) =
all_ok [
send env s2 count; send env s2 count; send env s2 count; send env s2 count;
Expand Down Expand Up @@ -124,15 +150,15 @@ let suite () =
in

__MODULE__ >::: [
"test_setup_teardown" >:: bracket test_setup_teardown;
"test_send_receive" >:: bracket test_send_receive;
"test_msend_mreceive" >:: bracket test_msend_mreceive;
"test_mix" >:: bracket test_mix;
"test_slow_send" >:: bracket test_slow_send;
"test_slow_receive" >:: bracket test_slow_receive;
"test_slow_mix" >:: bracket test_slow_mix1;
"test_slow_mix" >:: bracket test_slow_mix2;
"test_send_receive" >:: bracket test_send_receive;
"test_setup_teardown" >:: bracket test_setup_teardown;
"test_send_receive" >:: bracket test_send_receive;
"test_msend_mreceive" >:: bracket test_msend_mreceive;
"test_mix" >:: bracket test_mix;
"test_slow_send" >:: bracket test_slow_send;
"test_slow_receive" >:: bracket test_slow_receive;
"test_slow_mix" >:: bracket test_slow_mix1;
"test_slow_mix" >:: bracket test_slow_mix2;
"test_send_receive_all" >:: bracket test_send_receive_all;
]


Expand Down

0 comments on commit c94e954

Please sign in to comment.