From: Simon Brandhof Date: Fri, 12 May 2017 12:18:41 +0000 (+0200) Subject: Consistent safeguard timeouts in JUnit tests X-Git-Tag: 6.4-RC1~17 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=c3f190771bfaf1104985bdec74391599956bc66e;p=sonarqube.git Consistent safeguard timeouts in JUnit tests --- diff --git a/it/it-tests/src/test/java/it/serverSystem/RestartTest.java b/it/it-tests/src/test/java/it/serverSystem/RestartTest.java index 495836ce6f7..49007b2103c 100644 --- a/it/it-tests/src/test/java/it/serverSystem/RestartTest.java +++ b/it/it-tests/src/test/java/it/serverSystem/RestartTest.java @@ -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() { diff --git a/server/sonar-ce/src/test/java/org/sonar/ce/app/CeServerTest.java b/server/sonar-ce/src/test/java/org/sonar/ce/app/CeServerTest.java index 758c0eaf92d..c2a7f45c965 100644 --- a/server/sonar-ce/src/test/java/org/sonar/ce/app/CeServerTest.java +++ b/server/sonar-ce/src/test/java/org/sonar/ce/app/CeServerTest.java @@ -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(); diff --git a/server/sonar-ce/src/test/java/org/sonar/ce/cluster/HazelcastClientWrapperImplTest.java b/server/sonar-ce/src/test/java/org/sonar/ce/cluster/HazelcastClientWrapperImplTest.java index 75877871fa3..746b31960f6 100644 --- a/server/sonar-ce/src/test/java/org/sonar/ce/cluster/HazelcastClientWrapperImplTest.java +++ b/server/sonar-ce/src/test/java/org/sonar/ce/cluster/HazelcastClientWrapperImplTest.java @@ -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; diff --git a/server/sonar-ce/src/test/java/org/sonar/ce/taskprocessor/CeProcessingSchedulerImplTest.java b/server/sonar-ce/src/test/java/org/sonar/ce/taskprocessor/CeProcessingSchedulerImplTest.java index 43585cf63d1..355fd1c8267 100644 --- a/server/sonar-ce/src/test/java/org/sonar/ce/taskprocessor/CeProcessingSchedulerImplTest.java +++ b/server/sonar-ce/src/test/java/org/sonar/ce/taskprocessor/CeProcessingSchedulerImplTest.java @@ -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 diff --git a/server/sonar-process-monitor/src/test/java/org/sonar/application/SchedulerImplTest.java b/server/sonar-process-monitor/src/test/java/org/sonar/application/SchedulerImplTest.java index 349c5a09e8f..33c4cc2f0b9 100644 --- a/server/sonar-process-monitor/src/test/java/org/sonar/application/SchedulerImplTest.java +++ b/server/sonar-process-monitor/src/test/java/org/sonar/application/SchedulerImplTest.java @@ -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); diff --git a/server/sonar-process-monitor/src/test/java/org/sonar/application/cluster/AppStateClusterImplTest.java b/server/sonar-process-monitor/src/test/java/org/sonar/application/cluster/AppStateClusterImplTest.java index 8c89e6593e1..fd0497c4932 100644 --- a/server/sonar-process-monitor/src/test/java/org/sonar/application/cluster/AppStateClusterImplTest.java +++ b/server/sonar-process-monitor/src/test/java/org/sonar/application/cluster/AppStateClusterImplTest.java @@ -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 { diff --git a/server/sonar-process-monitor/src/test/java/org/sonar/application/cluster/HazelcastClusterTest.java b/server/sonar-process-monitor/src/test/java/org/sonar/application/cluster/HazelcastClusterTest.java index 3f7eb072808..cc8a0baab1c 100644 --- a/server/sonar-process-monitor/src/test/java/org/sonar/application/cluster/HazelcastClusterTest.java +++ b/server/sonar-process-monitor/src/test/java/org/sonar/application/cluster/HazelcastClusterTest.java @@ -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(); diff --git a/server/sonar-process-monitor/src/test/java/org/sonar/application/process/SQProcessTest.java b/server/sonar-process-monitor/src/test/java/org/sonar/application/process/SQProcessTest.java index 84433436aa6..c7eb9e26608 100644 --- a/server/sonar-process-monitor/src/test/java/org/sonar/application/process/SQProcessTest.java +++ b/server/sonar-process-monitor/src/test/java/org/sonar/application/process/SQProcessTest.java @@ -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() { diff --git a/server/sonar-process-monitor/src/test/java/org/sonar/application/process/StopRequestWatcherImplTest.java b/server/sonar-process-monitor/src/test/java/org/sonar/application/process/StopRequestWatcherImplTest.java index 3fbe5f8a52c..2ac305797e4 100644 --- a/server/sonar-process-monitor/src/test/java/org/sonar/application/process/StopRequestWatcherImplTest.java +++ b/server/sonar-process-monitor/src/test/java/org/sonar/application/process/StopRequestWatcherImplTest.java @@ -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); diff --git a/server/sonar-process/src/test/java/org/sonar/process/ProcessEntryPointTest.java b/server/sonar-process/src/test/java/org/sonar/process/ProcessEntryPointTest.java index 3b045b6a0dc..68996625c72 100644 --- a/server/sonar-process/src/test/java/org/sonar/process/ProcessEntryPointTest.java +++ b/server/sonar-process/src/test/java/org/sonar/process/ProcessEntryPointTest.java @@ -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(); diff --git a/server/sonar-process/src/test/java/org/sonar/process/ProcessUtilsTest.java b/server/sonar-process/src/test/java/org/sonar/process/ProcessUtilsTest.java index d1f872b904d..b88ca719cd5 100644 --- a/server/sonar-process/src/test/java/org/sonar/process/ProcessUtilsTest.java +++ b/server/sonar-process/src/test/java/org/sonar/process/ProcessUtilsTest.java @@ -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() { diff --git a/server/sonar-process/src/test/java/org/sonar/process/StopWatcherTest.java b/server/sonar-process/src/test/java/org/sonar/process/StopWatcherTest.java index 970a1e4bdc9..9938ae1050c 100644 --- a/server/sonar-process/src/test/java/org/sonar/process/StopWatcherTest.java +++ b/server/sonar-process/src/test/java/org/sonar/process/StopWatcherTest.java @@ -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 { diff --git a/server/sonar-search/src/test/java/org/sonar/search/SearchServerTest.java b/server/sonar-search/src/test/java/org/sonar/search/SearchServerTest.java index 88c1c1960a1..407a99ecc27 100644 --- a/server/sonar-search/src/test/java/org/sonar/search/SearchServerTest.java +++ b/server/sonar-search/src/test/java/org/sonar/search/SearchServerTest.java @@ -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(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/webhook/WebhookCallerImplTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/webhook/WebhookCallerImplTest.java index 9160e36eb30..4a7d4d829c3 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/webhook/WebhookCallerImplTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/webhook/WebhookCallerImplTest.java @@ -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); diff --git a/server/sonar-server/src/test/java/org/sonar/server/platform/db/EmbeddedDatabaseTest.java b/server/sonar-server/src/test/java/org/sonar/server/platform/db/EmbeddedDatabaseTest.java index bc59f3d1a8e..c11637b90af 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/platform/db/EmbeddedDatabaseTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/platform/db/EmbeddedDatabaseTest.java @@ -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); diff --git a/sonar-core/src/test/java/org/sonar/core/util/DefaultHttpDownloaderTest.java b/sonar-core/src/test/java/org/sonar/core/util/DefaultHttpDownloaderTest.java index 3c40e5dc698..77fa075d13f 100644 --- a/sonar-core/src/test/java/org/sonar/core/util/DefaultHttpDownloaderTest.java +++ b/sonar-core/src/test/java/org/sonar/core/util/DefaultHttpDownloaderTest.java @@ -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; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/util/ProgressReportTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/util/ProgressReportTest.java index d2283d0212c..f218a89b6cd 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/util/ProgressReportTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/util/ProgressReportTest.java @@ -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();