Skip to content

Test on OS X, Ubuntu, OCaml 4.01-4.03 in Travis. - #240

Merged
aantron merged 2 commits into
masterfrom
multiplatform-ci
May 12, 2016
Merged

aantron merged 2 commits into
masterfrom
multiplatform-ci

Conversation

@aantron

@aantron aantron commented May 6, 2016

Copy link
Copy Markdown
Collaborator

No description provided.

@Drup

Drup commented May 6, 2016

Copy link
Copy Markdown
Member

@aantron

aantron commented May 6, 2016

Copy link
Copy Markdown
Collaborator Author

Is it usable with MacPorts in Travis? Also, AFAIK, depext is not (yet) so commonly used, so I put some value on testing a build/install process that doesn't use it.

@Drup

Drup commented May 6, 2016

Copy link
Copy Markdown
Member

depext is optional, for the rest, read the travis/appveyor readme.

@aantron

aantron commented May 6, 2016

Copy link
Copy Markdown
Collaborator Author

I believe the script and the conf- packages need a bit of work to support MacPorts, but I prefer to do that later. Otherwise, I'm in favor of using it – will switch in the future.

@aantron
aantron force-pushed the multiplatform-ci branch from 3b87aa9 to edcac15 Compare May 8, 2016 00:25
@aantron

aantron commented May 8, 2016

Copy link
Copy Markdown
Collaborator Author

@nojb ideas for resolving this failure, besides assigning different ports to each test case or introducing delays? https://travis-ci.org/ocsigen/lwt/jobs/128587022#L448 Occurs sporadically on both Linux and OS X.

@nojb

nojb commented May 9, 2016

Copy link
Copy Markdown
Contributor

Hi sorry for the delay - will get back after I take a look today .

@nojb

nojb commented May 9, 2016

Copy link
Copy Markdown
Contributor

I don't manage to reproduce this locally. Any ideas/guess what could be the reason ? It looks like setting SO_REUSEADDR should have fixed it.

@nojb

nojb commented May 9, 2016

Copy link
Copy Markdown
Contributor

Hi @aantron,

I reworked the tests to make them more deterministic. Could you apply the diff below and check to see if the issue persists ?

Thanks!

diff --git a/tests/unix/test_mcast.ml b/tests/unix/test_mcast.ml
index 184c95e..cc40699 100644
--- a/tests/unix/test_mcast.ml
+++ b/tests/unix/test_mcast.ml
@@ -23,21 +23,19 @@
 open Lwt.Infix
 open Test

+let debug = false
 let hello = Bytes.unsafe_of_string "Hello, World!"
 let mcast_addr = "225.0.0.1"
 let mcast_port = 4321

-let with_fd f =
-  let fd = Lwt_unix.(socket PF_INET SOCK_DGRAM 0) in
-  Lwt.finalize (fun () -> f fd) (fun () -> Lwt_unix.close fd)
-
 let child join fd =
   (* Lwt_unix.setsockopt fd Lwt_unix.SO_REUSEADDR true; *)
   Lwt_unix.(bind fd (ADDR_INET (Unix.inet_addr_any, mcast_port)));
   if join then Lwt_unix.mcast_add_membership fd (Unix.inet_addr_of_string mcast_addr);
   let buf = Bytes.create 50 in
-  Lwt_unix.read fd buf 0 50 >>= fun n ->
-  (* Printf.printf "\nReceived multicast message %S\n%!" (Bytes.unsafe_to_string (Bytes.sub buf 0 n)); *)
+  Lwt_unix.with_timeout 0.1 (fun () -> Lwt_unix.read fd buf 0 (Bytes.length buf)) >>= fun n ->
+  if debug then
+    Printf.printf "\nReceived multicast message %S\n%!" (Bytes.unsafe_to_string (Bytes.sub buf 0 n));
   if Bytes.sub buf 0 n <> hello then
     Lwt.fail (Failure "unexpected multicast message")
   else
@@ -45,26 +43,33 @@ let child join fd =

 let parent set_loop fd =
   Lwt_unix.mcast_set_loop fd set_loop;
-  let rec loop () =
-    Lwt_unix.(sendto fd hello 0 (Bytes.length hello) []
-                (ADDR_INET (Unix.inet_addr_of_string mcast_addr, mcast_port))) >>= fun _ ->
-    (* Printf.printf "\nSending multicast message %S to %s:%d\n%!" (Bytes.unsafe_to_string hello) *)
-    (*   mcast_addr mcast_port; *)
-    Lwt_unix.sleep 0.2 >>= loop
-  in
-  loop ()
+  let addr = Lwt_unix.ADDR_INET (Unix.inet_addr_of_string mcast_addr, mcast_port) in
+  Lwt_unix.sendto fd hello 0 (Bytes.length hello) [] addr >>= fun _ ->
+  if debug then
+    Printf.printf "\nSending multicast message %S to %s:%d\n%!" (Bytes.unsafe_to_string hello)
+      mcast_addr mcast_port;
+  Lwt.return_unit

 let test_mcast join set_loop =
   let should_timeout = not join || not set_loop in
-  let t = Lwt_unix.with_timeout 0.5 (fun () -> Lwt.pick [ with_fd (child join); with_fd (parent set_loop) ]) in
-  Lwt.catch (fun () -> t >>= fun x -> Lwt.return (`Ok x)) (fun e -> Lwt.return (`Fail e)) >>= function
-  | `Fail Lwt_unix.Timeout ->
-    Lwt.return should_timeout
-  | `Fail e ->
-    Printf.eprintf "\ntest_mcast: unexpected failure: %S\n%!" (Printexc.to_string e);
-    Lwt.return false
-  | `Ok () ->
-    Lwt.return true
+  let fd1 = Lwt_unix.(socket PF_INET SOCK_DGRAM 0) in
+  let fd2 = Lwt_unix.(socket PF_INET SOCK_DGRAM 0) in
+  let t () =
+    Lwt.catch
+      (fun () ->
+         let t1 = child join fd1 in
+         let t2 = parent set_loop fd2 in
+         Lwt.join [t1; t2] >>= fun () -> Lwt.return true
+      )
+      (function
+        | Lwt_unix.Timeout ->
+          Lwt.return should_timeout
+        | e ->
+          Printf.eprintf "\ntest_mcast: unexpected failure: %S\n%!" (Printexc.to_string e);
+          Lwt.return false
+      )
+  in
+  Lwt.finalize t (fun () -> Lwt.join [Lwt_unix.close fd1; Lwt_unix.close fd2])

 let suite =
   suite "unix_mcast"

@aantron
aantron force-pushed the multiplatform-ci branch from edcac15 to 9afbb84 Compare May 10, 2016 14:13
@aantron

aantron commented May 10, 2016

Copy link
Copy Markdown
Collaborator Author

Thanks! I turned your diff into a commit – hope that is okay.

I also hadn't been able to reproduce it locally. If this fails, I will restore the REUSEADDR commit and try again, and if it succeeds, I will probably rebuild it several times to be more certain. So, it might take a while, but I will let you know how it goes.

@aantron

aantron commented May 11, 2016

Copy link
Copy Markdown
Collaborator Author

Okay, looks like your patch did it. Thanks again!

@aantron
aantron merged commit 9afbb84 into master May 12, 2016
@aantron
aantron deleted the multiplatform-ci branch May 17, 2016 14:38
@aantron aantron mentioned this pull request May 20, 2016
2 of 8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants