You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TB3Runner.java 2.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * Copyright 2000-2014 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.tests.tb3;
  17. import java.lang.reflect.Field;
  18. import java.lang.reflect.Modifier;
  19. import org.apache.http.client.HttpClient;
  20. import org.junit.runners.Parameterized;
  21. import org.junit.runners.model.InitializationError;
  22. import org.openqa.selenium.remote.internal.ApacheHttpClient;
  23. import org.openqa.selenium.remote.internal.HttpClientFactory;
  24. import com.vaadin.testbench.parallel.ParallelRunner;
  25. /**
  26. * This runner is loosely based on FactoryTestRunner by Ted Young
  27. * (http://tedyoung.me/2011/01/23/junit-runtime-tests-custom-runners/). The
  28. * generated test names give information about the parameters used (unlike
  29. * {@link Parameterized}).
  30. *
  31. * @since 7.1
  32. */
  33. public class TB3Runner extends ParallelRunner {
  34. /**
  35. * Socket timeout for HTTP connections to the grid hub. The connection is
  36. * closed after 30 minutes of inactivity to avoid builds hanging for up to
  37. * three hours per connection if the test client crashes/hangs.
  38. */
  39. private static final int SOCKET_TIMEOUT = 30 * 60 * 1000;
  40. static {
  41. // reduce socket timeout to avoid tests hanging for three hours
  42. try {
  43. Field field = ApacheHttpClient.Factory.class
  44. .getDeclaredField("defaultClientFactory");
  45. assert (Modifier.isStatic(field.getModifiers()));
  46. field.setAccessible(true);
  47. field.set(null, new HttpClientFactory() {
  48. @Override
  49. public HttpClient getGridHttpClient(int connection_timeout,
  50. int socket_timeout) {
  51. if (socket_timeout == 0 || socket_timeout > SOCKET_TIMEOUT) {
  52. return super.getGridHttpClient(connection_timeout,
  53. SOCKET_TIMEOUT);
  54. }
  55. return super.getGridHttpClient(connection_timeout,
  56. socket_timeout);
  57. }
  58. });
  59. } catch (Exception e) {
  60. e.printStackTrace();
  61. throw new RuntimeException(
  62. "Changing socket timeout for TestBench failed", e);
  63. }
  64. }
  65. public TB3Runner(Class<?> klass) throws InitializationError {
  66. super(klass);
  67. }
  68. }