]> source.dussan.org Git - sonarqube.git/commitdiff
Consistent safeguard timeouts in JUnit tests
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Fri, 12 May 2017 12:18:41 +0000 (14:18 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Fri, 12 May 2017 12:18:41 +0000 (14:18 +0200)
17 files changed:
it/it-tests/src/test/java/it/serverSystem/RestartTest.java
server/sonar-ce/src/test/java/org/sonar/ce/app/CeServerTest.java
server/sonar-ce/src/test/java/org/sonar/ce/cluster/HazelcastClientWrapperImplTest.java
server/sonar-ce/src/test/java/org/sonar/ce/taskprocessor/CeProcessingSchedulerImplTest.java
server/sonar-process-monitor/src/test/java/org/sonar/application/SchedulerImplTest.java
server/sonar-process-monitor/src/test/java/org/sonar/application/cluster/AppStateClusterImplTest.java
server/sonar-process-monitor/src/test/java/org/sonar/application/cluster/HazelcastClusterTest.java
server/sonar-process-monitor/src/test/java/org/sonar/application/process/SQProcessTest.java
server/sonar-process-monitor/src/test/java/org/sonar/application/process/StopRequestWatcherImplTest.java
server/sonar-process/src/test/java/org/sonar/process/ProcessEntryPointTest.java
server/sonar-process/src/test/java/org/sonar/process/ProcessUtilsTest.java
server/sonar-process/src/test/java/org/sonar/process/StopWatcherTest.java
server/sonar-search/src/test/java/org/sonar/search/SearchServerTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/webhook/WebhookCallerImplTest.java
server/sonar-server/src/test/java/org/sonar/server/platform/db/EmbeddedDatabaseTest.java
sonar-core/src/test/java/org/sonar/core/util/DefaultHttpDownloaderTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/util/ProgressReportTest.java

index 495836ce6f75aa88925d4d820c369aa6191fec3e..49007b2103c775272a4c8a9bb0bb608bb94ce23f 100644 (file)
@@ -51,7 +51,7 @@ public class RestartTest {
   @Rule
   public ExpectedException thrown = ExpectedException.none();
   @Rule
-  public TestRule globalTimeout = new DisableOnDebug(Timeout.seconds(900L));
+  public TestRule safeguardTimeout = new DisableOnDebug(Timeout.seconds(60));
 
   @After
   public void stop() {
index 758c0eaf92d3e936a9f1d5ba617d542ac67c7a83..c2a7f45c965905077fbd577c04e84ed6141a9dea 100644 (file)
@@ -27,7 +27,9 @@ import javax.annotation.Nullable;
 import org.junit.After;
 import org.junit.Rule;
 import org.junit.Test;
+import org.junit.rules.DisableOnDebug;
 import org.junit.rules.ExpectedException;
+import org.junit.rules.TestRule;
 import org.junit.rules.Timeout;
 import org.mockito.Mockito;
 import org.sonar.ce.ComputeEngine;
@@ -41,7 +43,7 @@ import static org.mockito.Mockito.mock;
 
 public class CeServerTest {
   @Rule
-  public Timeout timeout = Timeout.seconds(50);
+  public TestRule safeguardTimeout = new DisableOnDebug(Timeout.seconds(60));
   @Rule
   public ExpectedException expectedException = ExpectedException.none();
 
index 75877871fa39734a0082be6ae47549d77e2456c4..746b31960f6fbdb6c883e6dd5eb79c0efac835e1 100644 (file)
@@ -60,7 +60,7 @@ public class HazelcastClientWrapperImplTest {
   public ExpectedException expectedException = ExpectedException.none();
 
   @Rule
-  public TestRule safeGuard = new DisableOnDebug(Timeout.seconds(20));
+  public TestRule safeguardTimeout = new DisableOnDebug(Timeout.seconds(60));
 
   private static HazelcastInstance hzCluster;
   private static HazelcastClientWrapperImpl hzClient;
index 43585cf63d12df9e3c5465e46bf548b417321208..355fd1c8267dd178f4f62f4af1e36cef7db2ec5c 100644 (file)
@@ -44,6 +44,8 @@ import javax.annotation.Nullable;
 import javax.annotation.concurrent.Immutable;
 import org.junit.Rule;
 import org.junit.Test;
+import org.junit.rules.DisableOnDebug;
+import org.junit.rules.TestRule;
 import org.junit.rules.Timeout;
 import org.sonar.ce.configuration.CeConfigurationRule;
 
@@ -64,7 +66,7 @@ public class CeProcessingSchedulerImplTest {
 
   @Rule
   // due to risks of infinite chaining of tasks/futures, a timeout is required for safety
-  public Timeout timeout = Timeout.seconds(60);
+  public TestRule safeguardTimeout = new DisableOnDebug(Timeout.seconds(60));
   @Rule
   public CeConfigurationRule ceConfiguration = new CeConfigurationRule();
   // Required to prevent an infinite loop
index 349c5a09e8ff4dd6bfd36a25b1e4523bd9968b41..33c4cc2f0b9cafa59ac5d450c823e4b68345bc92 100644 (file)
@@ -58,7 +58,7 @@ public class SchedulerImplTest {
   private static final JavaCommand CE_COMMAND = new JavaCommand(COMPUTE_ENGINE);
 
   @Rule
-  public TestRule safeGuard = new DisableOnDebug(Timeout.seconds(30));
+  public TestRule safeguardTimeout = new DisableOnDebug(Timeout.seconds(60));
   @Rule
   public ExpectedException expectedException = ExpectedException.none();
 
@@ -187,7 +187,7 @@ public class SchedulerImplTest {
     }
 
     // restarting
-    verify(appReloader, timeout(10_000)).reload(settings);
+    verify(appReloader, timeout(60_000)).reload(settings);
     processLauncher.waitForProcessAlive(ELASTICSEARCH);
     processLauncher.waitForProcessAlive(COMPUTE_ENGINE);
     processLauncher.waitForProcessAlive(WEB_SERVER);
index 8c89e6593e1ecee99477f7b9498b1056c84eb41a..fd0497c4932ad5c9c93ab27081ab176cd178995b 100644 (file)
@@ -49,7 +49,7 @@ public class AppStateClusterImplTest {
   public ExpectedException expectedException = ExpectedException.none();
 
   @Rule
-  public TestRule safeGuard = new DisableOnDebug(Timeout.seconds(10));
+  public TestRule safeguardTimeout = new DisableOnDebug(Timeout.seconds(60));
 
   @Test
   public void instantiation_throws_ISE_if_cluster_mode_is_disabled() throws Exception {
index 3f7eb072808ee019f6536ebe167353084865d421..cc8a0baab1cae3072ba3f3af87ca655dfc032068 100644 (file)
@@ -63,7 +63,7 @@ import static org.sonar.process.cluster.ClusterObjectKeys.SONARQUBE_VERSION;
 
 public class HazelcastClusterTest {
   @Rule
-  public TestRule safeGuard = new DisableOnDebug(Timeout.seconds(10));
+  public TestRule safeguardTimeout = new DisableOnDebug(Timeout.seconds(60));
 
   @Rule
   public ExpectedException expectedException = ExpectedException.none();
index 84433436aa6b8dc8e245236ccd2e15afeacd7a24..c7eb9e2660865f14e3563e19779122a378556649 100644 (file)
@@ -44,7 +44,7 @@ public class SQProcessTest {
   @Rule
   public ExpectedException expectedException = ExpectedException.none();
   @Rule
-  public TestRule safeGuard = new DisableOnDebug(Timeout.seconds(10));
+  public TestRule safeguardTimeout = new DisableOnDebug(Timeout.seconds(60));
 
   @Test
   public void initial_state_is_INIT() {
index 3fbe5f8a52c65a2ea06d1672b678b86066bbcafe..2ac305797e49c6dc4198f615ca6f1a1f26700195 100644 (file)
@@ -46,7 +46,7 @@ public class StopRequestWatcherImplTest {
   @Rule
   public TemporaryFolder temp = new TemporaryFolder();
   @Rule
-  public TestRule safeGuard = new DisableOnDebug(Timeout.seconds(10));
+  public TestRule safeguardTimeout = new DisableOnDebug(Timeout.seconds(60));
 
   private AppSettings settings = mock(AppSettings.class, RETURNS_DEEP_STUBS);
   private ProcessCommands commands = mock(ProcessCommands.class);
index 3b045b6a0dc1255f1bc6881592b791b8966a5427..68996625c72248ed42491515ada596e76f8ed7e6 100644 (file)
@@ -43,13 +43,10 @@ import static org.sonar.process.ProcessEntryPoint.PROPERTY_TERMINATION_TIMEOUT;
 
 public class ProcessEntryPointTest {
 
-  SystemExit exit = mock(SystemExit.class);
+  private SystemExit exit = mock(SystemExit.class);
 
-  /**
-   * Safeguard
-   */
   @Rule
-  public TestRule timeout = new DisableOnDebug(Timeout.seconds(60));
+  public TestRule safeguardTimeout = new DisableOnDebug(Timeout.seconds(60));
 
   @Rule
   public TemporaryFolder temp = new TemporaryFolder();
index d1f872b904db527111afa3750a0503e48740490c..b88ca719cd5af393c4bb3c140b02ccc81ca7e51a 100644 (file)
@@ -21,6 +21,8 @@ package org.sonar.process;
 
 import org.junit.Rule;
 import org.junit.Test;
+import org.junit.rules.DisableOnDebug;
+import org.junit.rules.TestRule;
 import org.junit.rules.Timeout;
 import org.sonar.test.TestUtils;
 
@@ -30,7 +32,7 @@ import static org.sonar.process.ProcessUtils.awaitTermination;
 public class ProcessUtilsTest {
 
   @Rule
-  public Timeout timeout = Timeout.seconds(5);
+  public TestRule safeguardTimeout = new DisableOnDebug(Timeout.seconds(60));
 
   @Test
   public void private_constructor() {
index 970a1e4bdc9e5db5c30a6f0434ed85184a9bb201..9938ae1050cb31ec693cefa1cbfbcae326272d79 100644 (file)
@@ -33,7 +33,7 @@ import static org.mockito.Mockito.when;
 public class StopWatcherTest {
 
   @Rule
-  public TestRule safeguard = new DisableOnDebug(Timeout.seconds(10));
+  public TestRule safeguardTimeout = new DisableOnDebug(Timeout.seconds(60));
 
   @Test
   public void stop_if_receive_command() throws Exception {
index 88c1c1960a1ee80c3ded6aa518be2514196c4c9c..407a99ecc2712a67e4218a831902732c14214ac3 100644 (file)
@@ -55,7 +55,7 @@ public class SearchServerTest {
   private static final String A_NODE_NAME = "a_node";
 
   @Rule
-  public TestRule timeout = new DisableOnDebug(Timeout.seconds(60));
+  public TestRule safeguardTimeout = new DisableOnDebug(Timeout.seconds(60));
 
   @Rule
   public TemporaryFolder temp = new TemporaryFolder();
index 9160e36eb30e26d0add19365c4376f7bebd9c37d..4a7d4d829c38bbea73086cb390c17c5d6a520a14 100644 (file)
@@ -51,7 +51,7 @@ public class WebhookCallerImplTest {
   public MockWebServer server = new MockWebServer();
 
   @Rule
-  public TestRule timeoutSafeguard = new DisableOnDebug(Timeout.seconds(60));
+  public TestRule safeguardTimeout = new DisableOnDebug(Timeout.seconds(60));
 
   private System2 system = new TestSystem2().setNow(NOW);
 
index bc59f3d1a8e1f5549521fbc61935264357181201..c11637b90af49b6a7d16dcb8a97d30104c26fe90 100644 (file)
@@ -58,7 +58,7 @@ public class EmbeddedDatabaseTest {
   @Rule
   public TemporaryFolder temporaryFolder = new TemporaryFolder();
   @Rule
-  public TestRule safeguard = new DisableOnDebug(Timeout.seconds(30));
+  public TestRule safeguardTimeout = new DisableOnDebug(Timeout.seconds(60));
 
   private MapSettings settings = new MapSettings();
   private System2 system2 = mock(System2.class);
index 3c40e5dc6988f69f9f06bd828d06ffbe3dd3b210..77fa075d13f22594a469856f3296d209ca18191b 100644 (file)
@@ -76,7 +76,7 @@ public class DefaultHttpDownloaderTest {
   public ExpectedException thrown = ExpectedException.none();
 
   @Rule
-  public TestRule timeout = new DisableOnDebug(Timeout.seconds(60));
+  public TestRule safeguardTimeout = new DisableOnDebug(Timeout.seconds(60));
 
   private static SocketConnection socketConnection;
   private static String baseUrl;
index d2283d0212cc8a5e82a89786eb54918ee43ec984..f218a89b6cdca96437390bb01b0ff5a2ef8efbff 100644 (file)
@@ -33,7 +33,7 @@ public class ProgressReportTest {
   private static final String THREAD_NAME = "progress";
 
   @Rule
-  public TestRule timeoutSafeguard = new DisableOnDebug(Timeout.seconds(10));
+  public TestRule safeguardTimeout = new DisableOnDebug(Timeout.seconds(60));
   @Rule
   public LogTester logTester = new LogTester();