Fix flaky MessageTransport test (again).

It is possible that an IOException can occur in this test. Also, get rid of a redundant test.

Review by: kjin@google.com

git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@7772 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/dev/core/test/com/google/gwt/dev/shell/remoteui/MessageTransportTest.java b/dev/core/test/com/google/gwt/dev/shell/remoteui/MessageTransportTest.java
index befc8cb..7f41a84 100644
--- a/dev/core/test/com/google/gwt/dev/shell/remoteui/MessageTransportTest.java
+++ b/dev/core/test/com/google/gwt/dev/shell/remoteui/MessageTransportTest.java
@@ -83,18 +83,15 @@
   }
 
   /**
-   * Tests that sending an async request to a server when the sending stream is
-   * closed will result in:
-   * 
-   * 1) A rejection of the request to the executor 2) An ExecutionException on a
-   * call to future.get()
+   * Tests that sending an async request to a server when the server's socket is
+   * closed with result in an ExecutionException on a call to future.get().
    * 
    * @throws ExecutionException
    * @throws InterruptedException
    * @throws IOException
    */
-  public void testExecuteAsyncRequestWithClosedSendStream() throws IOException,
-      InterruptedException, ExecutionException {
+  public void testExecuteAsyncRequestWithClosedServerSocket()
+      throws IOException, InterruptedException, ExecutionException {
     MockNetwork network = createMockNetwork();
 
     /*
@@ -135,8 +132,7 @@
       sleepCycles++;
     }
 
-    assertTrue(
-        "Unable to shut down server's input stream; cannot proceed with the test.",
+    assertTrue("Unable to close socket; cannot proceed with the test.",
         network.getServerSocket().isClosed());
 
     Future<Response> responseFuture = null;
@@ -149,8 +145,15 @@
     } catch (TimeoutException te) {
       fail("Should not have timed out");
     } catch (ExecutionException e) {
-      assertTrue("Expected: IllegalStateException, actual:" + e.getCause(),
-          e.getCause() instanceof IllegalStateException);
+      /*
+       * An IOException can happen if the request gets in the queue before the
+       * message processing thread terminates. If the request gets in the queue
+       * after the message processing thread terminates, then the result will be
+       * an IllegalStateException.
+       */
+      assertTrue("Expected: IllegalStateException or IOException, actual:"
+          + e.getCause(), e.getCause() instanceof IllegalStateException
+          || e.getCause() instanceof IOException);
     } catch (Exception e) {
       fail("Should not have thrown any other exception");
     }
@@ -308,62 +311,6 @@
   }
 
   /**
-   * Tests that a future for an async request to a remote server will be
-   * interrupted if the server closes the connection before the response is
-   * received.
-   */
-  public void testExecuteRequestAsyncWithClosedReceiveStreamBeforeResponse()
-      throws IOException, InterruptedException, ExecutionException,
-      TimeoutException {
-    MockNetwork network = createMockNetwork();
-
-    /*
-     * Define a dummy request processor. The message transport is being set up
-     * on the client side, which means that it should not be receiving any
-     * requests (any responses).
-     */
-    RequestProcessor requestProcessor = new RequestProcessor() {
-      public Response execute(Request request) throws Exception {
-        fail("Should not reach here.");
-        return null;
-      }
-    };
-
-    // Set up a message transport on the client side
-    MessageTransport messageTransport = new MessageTransport(
-        network.getClientSocket().getInputStream(),
-        network.getClientSocket().getOutputStream(), requestProcessor,
-        new MessageTransport.TerminationCallback() {
-          public void onTermination(Exception e) {
-          }
-        });
-    messageTransport.start();
-
-    Message.Request.Builder requestMessageBuilder = Message.Request.newBuilder();
-    requestMessageBuilder.setServiceType(Message.Request.ServiceType.DEV_MODE);
-    Message.Request request = requestMessageBuilder.build();
-
-    // This will close the client's input stream
-    network.getServerSocket().getOutputStream().close();
-
-    try {
-      Future<Response> response = messageTransport.executeRequestAsync(request);
-      response.get(2, TimeUnit.SECONDS);
-      fail("Should have thrown an exception");
-    } catch (TimeoutException te) {
-      fail("Should not have timed out");
-    } catch (ExecutionException e) {
-      // This is where we should hit
-      assertTrue("Expected: IllegalStateException, actual:" + e.getCause(),
-          e.getCause() instanceof IllegalStateException);
-    } catch (Exception e) {
-      fail("Should not have thrown any other exception");
-    }
-
-    network.shutdown();
-  }
-
-  /**
    * Tests that a client request is successfully received by the
    * RequestProcessor, and the response generated by the RequestProcessor is
    * successfully received by the client.