aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorantoine.vinot <antoine.vinot@sonarsource.com>2023-08-09 10:45:45 +0200
committersonartech <sonartech@sonarsource.com>2023-10-03 20:02:37 +0000
commit71e16f0ed979316b1bb22cc62cace5aef88a2f7f (patch)
treeabf4189d3ca261ea5451b8c7ffa2ca2be948367a
parent251ae0c7263fe913e31e241e9d04f03bffd39f80 (diff)
downloadsonarqube-71e16f0ed979316b1bb22cc62cace5aef88a2f7f.tar.gz
sonarqube-71e16f0ed979316b1bb22cc62cace5aef88a2f7f.zip
SONAR-20056 - Fix flaky test on constructor_does_not_start_a_new_Thread
(cherry picked from commit 2113d3b3b42751f8ccabee6000d92bdb3b4b2f29)
-rw-r--r--server/sonar-ce/src/test/java/org/sonar/ce/app/CeServerTest.java19
1 files changed, 10 insertions, 9 deletions
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 64ecfd64c74..492dcc12f59 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
@@ -54,8 +54,8 @@ public class CeServerTest {
private CeServer underTest = null;
private Thread waitingThread = null;
- private MinimumViableSystem minimumViableSystem = mock(MinimumViableSystem.class, Mockito.RETURNS_MOCKS);
- private CeSecurityManager ceSecurityManager = mock(CeSecurityManager.class);
+ private final MinimumViableSystem minimumViableSystem = mock(MinimumViableSystem.class, Mockito.RETURNS_MOCKS);
+ private final CeSecurityManager ceSecurityManager = mock(CeSecurityManager.class);
@After
public void tearDown() throws Exception {
@@ -71,9 +71,9 @@ public class CeServerTest {
@Test
public void constructor_does_not_start_a_new_Thread() {
- int activeCount = Thread.activeCount();
+ assertThat(ceThreadExists()).isFalse();
newCeServer();
- assertThat(Thread.activeCount()).isSameAs(activeCount);
+ assertThat(ceThreadExists()).isFalse();
}
@Test
@@ -93,11 +93,9 @@ public class CeServerTest {
@Test
public void start_starts_a_new_Thread() {
- int activeCount = Thread.activeCount();
-
+ assertThat(ceThreadExists()).isFalse();
newCeServer().start();
-
- assertThat(Thread.activeCount()).isSameAs(activeCount + 1);
+ assertThat(ceThreadExists()).isTrue();
}
@Test
@@ -122,7 +120,10 @@ public class CeServerTest {
}
private static boolean ceThreadExists() {
- return Thread.getAllStackTraces().keySet().stream().anyMatch(t -> t.getName().equals("ce-main"));
+ return Thread.getAllStackTraces().keySet()
+ .stream()
+ .map(Thread::getName)
+ .anyMatch("ce-main"::equals);
}
@Test