Skip to content

Commit 28d6641

Browse files
committed
Allow to skip server and client test on Opam CI
1 parent 8e280da commit 28d6641

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

test/test_server_and_client.ml

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ let set_nonblock fd =
1616
try Unix.set_nonblock fd
1717
with _exn -> Printf.printf " (Failed to set_nonblock)\n%!"
1818

19+
let is_opam_ci =
20+
match Sys.getenv "OPAM_REPO_CI" with
21+
| _ -> true
22+
| exception Not_found -> false
23+
1924
let main () =
2025
Bundle.run @@ fun bundle ->
2126
let n = 100 in
@@ -31,11 +36,13 @@ let main () =
3136
Unix.socket ~cloexec:true PF_INET SOCK_STREAM 0
3237
in
3338
set_nonblock socket;
34-
Unix.bind socket Unix.(ADDR_INET (inet_addr_loopback, 0));
35-
server_addr := Some (Unix.getsockname socket);
36-
Unix.listen socket 1;
37-
Printf.printf " Server listening\n%!";
38-
Unix.accept ~cloexec:true socket |> fst
39+
match Unix.bind socket Unix.(ADDR_INET (inet_addr_loopback, 0)) with
40+
| () ->
41+
server_addr := Some (Unix.getsockname socket);
42+
Unix.listen socket 1;
43+
Printf.printf " Server listening\n%!";
44+
Unix.accept ~cloexec:true socket |> fst
45+
| exception Unix.Unix_error (EPERM, _, _) when is_opam_ci -> raise Exit
3946
in
4047
set_nonblock client;
4148
let bytes = Bytes.create n in
@@ -57,7 +64,8 @@ let main () =
5764
let rec loop retries =
5865
match !server_addr with
5966
| None ->
60-
if retries < 0 then failwith "No server address";
67+
if retries < 0 then
68+
if is_opam_ci then raise Exit else failwith "No server address";
6169
Sleep.sleepf 0.01;
6270
loop (retries - 1)
6371
| Some addr -> addr
@@ -81,4 +89,5 @@ let () =
8189
Printf.printf "Using %sblocking sockets and %s:\n%!"
8290
(if use_nonblock then "non-" else "")
8391
(if is_ocaml4 then "threads on OCaml 4" else "fibers on OCaml 5");
84-
Test_scheduler.run main
92+
try Test_scheduler.run main
93+
with Exit -> Printf.printf "Server and Client test: SKIPPED\n%!"

0 commit comments

Comments
 (0)