]> source.dussan.org Git - vaadin-framework.git/commitdiff
Reduce TestBench 3 socket timeout (#14298)
authorHenri Sara <hesara@vaadin.com>
Fri, 25 Jul 2014 11:29:42 +0000 (14:29 +0300)
committerVaadin Code Review <review@vaadin.com>
Mon, 28 Jul 2014 12:37:09 +0000 (12:37 +0000)
Change-Id: I45907c5c22bcea1a403af71ecbf5236e5669ab38

uitest/src/com/vaadin/tests/tb3/TB3Runner.java

index 5b5a6dcf39072433a2c1762112243cf1f637dc9a..4241b9fa6c6c2ec6ca12cc94f967fc40043b0880 100644 (file)
 package com.vaadin.tests.tb3;
 
 import java.lang.annotation.Annotation;
+import java.lang.reflect.Field;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.LinkedList;
@@ -26,6 +28,8 @@ import java.util.List;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 
+import org.apache.http.params.HttpConnectionParams;
+import org.apache.http.params.HttpParams;
 import org.junit.Ignore;
 import org.junit.Test;
 import org.junit.runners.BlockJUnit4ClassRunner;
@@ -34,6 +38,8 @@ import org.junit.runners.model.FrameworkMethod;
 import org.junit.runners.model.InitializationError;
 import org.junit.runners.model.Statement;
 import org.openqa.selenium.remote.DesiredCapabilities;
+import org.openqa.selenium.remote.HttpCommandExecutor;
+import org.openqa.selenium.remote.internal.HttpClientFactory;
 
 import com.vaadin.tests.annotations.TestCategory;
 import com.vaadin.tests.tb3.AbstractTB3Test.BrowserUtil;
@@ -49,6 +55,13 @@ import com.vaadin.tests.tb3.MultiBrowserTest.Browser;
  */
 public class TB3Runner extends BlockJUnit4ClassRunner {
 
+    /**
+     * Socket timeout for HTTP connections to the grid hub. The connection is
+     * closed after 15 minutes of inactivity to avoid builds hanging for up to
+     * three hours per connection if the test client crashes/hangs.
+     */
+    private static final int SOCKET_TIMEOUT = 15 * 60 * 1000;
+
     /**
      * This is the total limit of actual JUnit test instances run in parallel
      */
@@ -67,12 +80,34 @@ public class TB3Runner extends BlockJUnit4ClassRunner {
             MAX_CONCURRENT_TESTS = 50;
         }
         service = Executors.newFixedThreadPool(MAX_CONCURRENT_TESTS);
+
+        // reduce socket timeout to avoid tests hanging for three hours
+        try {
+            Field field = HttpCommandExecutor.class
+                    .getDeclaredField("httpClientFactory");
+            assert (Modifier.isStatic(field.getModifiers()));
+            field.setAccessible(true);
+            field.set(null, new HttpClientFactory() {
+                @Override
+                public HttpParams getHttpParams() {
+                    HttpParams params = super.getHttpParams();
+                    // fifteen minute timeout
+                    HttpConnectionParams.setSoTimeout(params, SOCKET_TIMEOUT);
+                    return params;
+                }
+            });
+        } catch (Exception e) {
+            e.printStackTrace();
+            throw new RuntimeException(
+                    "Changing socket timeout for TestBench failed", e);
+        }
     }
 
     protected static boolean localWebDriverIsUsed() {
         String useLocalWebDriver = System.getProperty("useLocalWebDriver");
 
-        return useLocalWebDriver != null && useLocalWebDriver.toLowerCase().equals("true");
+        return useLocalWebDriver != null
+                && useLocalWebDriver.toLowerCase().equals("true");
     }
 
     public TB3Runner(Class<?> klass) throws InitializationError {