Adjust test timeout value based on Batching Strategy.

Patch by: amitmanjhi
Review by: jlabanca



git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@6523 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/gwt/junit/BatchingStrategy.java b/user/src/com/google/gwt/junit/BatchingStrategy.java
index 96551e4..df9cec2 100644
--- a/user/src/com/google/gwt/junit/BatchingStrategy.java
+++ b/user/src/com/google/gwt/junit/BatchingStrategy.java
@@ -71,6 +71,15 @@
     toExecute.removeAll(toRemove);
     return toExecute;
   }
+
+  /**
+   * Returns the multiplicative factor for adjusting the timeout. Default value
+   * of 1 for no batching.
+   */
+  protected int getTimeoutMultiplier() {
+    return 1;
+  }
+
 }
 
 /**
@@ -130,6 +139,11 @@
   public boolean isSingleTestOnly() {
     return false;
   }
+  
+  @Override
+  protected int getTimeoutMultiplier() {
+    return 4;
+  }
 }
 
 /**
@@ -151,4 +165,9 @@
   public boolean isSingleTestOnly() {
     return false;
   }
+  
+  @Override
+  protected int getTimeoutMultiplier() {
+    return 4;
+  }
 }
diff --git a/user/src/com/google/gwt/junit/JUnitShell.java b/user/src/com/google/gwt/junit/JUnitShell.java
index b859554..d832f46 100644
--- a/user/src/com/google/gwt/junit/JUnitShell.java
+++ b/user/src/com/google/gwt/junit/JUnitShell.java
@@ -330,9 +330,9 @@
   /**
    * The amount of time to wait for all clients to complete a single test
    * method, in milliseconds, measured from when the <i>last</i> client connects
-   * (and thus starts the test). 20 minutes.
+   * (and thus starts the test). default of 5 minutes.
    */
-  private static final long TEST_METHOD_TIMEOUT_MILLIS = 4 * 300000;
+  private static final long TEST_METHOD_TIMEOUT_MILLIS = 300000;
 
   /**
    * Singleton object for hosting unit tests. All test case instances executed
@@ -529,6 +529,11 @@
    * Determines how to batch up tests for execution.
    */
   private BatchingStrategy batchingStrategy = new NoBatchingStrategy();
+  
+  /**
+   * Timeout in presence of batching. reassigned later.
+   */
+  private long testBatchingMethodTimeoutMillis = TEST_METHOD_TIMEOUT_MILLIS;
 
   /**
    * Determines how modules are compiled.
@@ -729,13 +734,13 @@
        */
       lastModule = currentModule;
       if (testMethodTimeout == 0) {
-        testMethodTimeout = currentTimeMillis + TEST_METHOD_TIMEOUT_MILLIS;
+        testMethodTimeout = currentTimeMillis + testBatchingMethodTimeoutMillis;
       } else if (testMethodTimeout < currentTimeMillis) {
         double elapsed = (currentTimeMillis - testBeginTime) / 1000.0;
         throw new TimeoutException(
             "The browser did not complete the test method "
                 + currentTestInfo.toString() + " in "
-                + TEST_METHOD_TIMEOUT_MILLIS
+                + testBatchingMethodTimeoutMillis
                 + "ms.\n  We have no results from:\n"
                 + messageQueue.getWorkingClients(currentTestInfo)
                 + "Actual time elapsed: " + elapsed + " seconds.\n");
@@ -915,6 +920,8 @@
   private void runTestImpl(GWTTestCase testCase, TestResult testResult)
       throws UnableToCompleteException {
 
+    testBatchingMethodTimeoutMillis = batchingStrategy.getTimeoutMultiplier()
+        * TEST_METHOD_TIMEOUT_MILLIS; 
     if (mustNotExecuteTest(getBannedPlatforms(testCase.getClass(),
         testCase.getName()))) {
       return;