Revision: 5469
Author:   [email protected]
Date:     Tue Jul  2 12:03:10 2013
Log:      trying to diagnose localserver port flakiness
https://codereview.appspot.com/10761046

sometimes a browser test starts a local http server, then fails to
get the port number for that server, and the symptom is the
browser test tries to load http://localhost:-1/... which fails
since that isn't a valid URL.

the getPort failure is happening after the localserver is
started successfully (because I have a log message that the server
has started, and the timestamp is shortly before the message that
we're about to load the invalid URL.)

I don't have any good theories why this is happening. getting port=-1
is possible if the local server has stopped, but that isn't something
we're doing, there aren't any messages that look like the server is
stopping abnormally, and I can't think of any way for that to happen.

lacking any good theories, I'm adding some code that might help
diagnose the problem.

R=kpreid2


http://code.google.com/p/google-caja/source/detail?r=5469

Modified:
 /trunk/tests/com/google/caja/util/LocalServer.java

=======================================
--- /trunk/tests/com/google/caja/util/LocalServer.java Mon Apr 22 10:43:32 2013 +++ /trunk/tests/com/google/caja/util/LocalServer.java Tue Jul 2 12:03:10 2013
@@ -14,6 +14,8 @@

 package com.google.caja.util;

+import java.util.Arrays;
+
 import org.mortbay.jetty.Server;
 import org.mortbay.jetty.handler.ContextHandler;
 import org.mortbay.jetty.handler.ResourceHandler;
@@ -23,6 +25,7 @@
 import org.mortbay.jetty.servlet.Context;
 import org.mortbay.jetty.servlet.ServletHolder;

+import com.google.caja.SomethingWidgyHappenedError;
 import com.google.caja.service.CajolingService;
 import com.google.caja.service.CajolingServlet;

@@ -45,7 +48,15 @@
   }

   public int getPort() {
-    return server.getConnectors()[0].getLocalPort();
+    int port = server.getConnectors()[0].getLocalPort();
+ // Occasionally port is -1 after the server is started, not sure why yet.
+    if (port < 0) {
+      throw new SomethingWidgyHappenedError(
+          "port=" + port +
+          " server=" + server +
+          " connectors=" + Arrays.toString(server.getConnectors()));
+    }
+    return port;
   }

   /**

--

--- You received this message because you are subscribed to the Google Groups "Google Caja Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to