]> source.dussan.org Git - sonarqube.git/commitdiff
Improve test isolation
authorJulien HENRY <julien.henry@sonarsource.com>
Thu, 3 Aug 2017 13:02:55 +0000 (15:02 +0200)
committerJulien HENRY <julien.henry@sonarsource.com>
Thu, 7 Sep 2017 06:33:31 +0000 (08:33 +0200)
When some assertions fail, components are not stopped, and that lead to failures in other tests.

server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java

index 130b892622b02e05524d4077dc8d24969f9960c6..0215ca1c13451572cc4c9660d5b6998bee0f0749 100644 (file)
@@ -96,13 +96,16 @@ public class ComputeEngineContainerImplTest {
     underTest
       .start(new Props(properties));
 
-    MutablePicoContainer picoContainer = underTest.getComponentContainer().getPicoContainer();
-    assertThat(
-      picoContainer.getComponentAdapters().stream()
-        .map(ComponentAdapter::getComponentImplementation)
-        .collect(Collectors.toList())).contains((Class) HazelcastClientWrapperImpl.class,
-          (Class) CeDistributedInformationImpl.class);
-    underTest.stop();
+    try {
+      MutablePicoContainer picoContainer = underTest.getComponentContainer().getPicoContainer();
+      assertThat(
+        picoContainer.getComponentAdapters().stream()
+          .map(ComponentAdapter::getComponentImplementation)
+          .collect(Collectors.toList())).contains((Class) HazelcastClientWrapperImpl.class,
+            (Class) CeDistributedInformationImpl.class);
+    } finally {
+      underTest.stop();
+    }
   }
 
   @Test
@@ -116,44 +119,48 @@ public class ComputeEngineContainerImplTest {
     underTest
       .start(new Props(properties));
     MutablePicoContainer picoContainer = underTest.getComponentContainer().getPicoContainer();
-    assertThat(picoContainer.getComponentAdapters())
-      .hasSize(
+
+    try {
+      assertThat(picoContainer.getComponentAdapters())
+        .hasSize(
+          CONTAINER_ITSELF
+            + 72 // level 4
+            + 4 // content of CeConfigurationModule
+            + 4 // content of CeQueueModule
+            + 4 // content of CeHttpModule
+            + 3 // content of CeTaskCommonsModule
+            + 4 // content of ProjectAnalysisTaskModule
+            + 5 // content of CeTaskProcessorModule
+            + 3 // CeCleaningModule + its content
+            + 1 // CeDistributedInformation
+      );
+      assertThat(picoContainer.getParent().getComponentAdapters()).hasSize(
+        CONTAINER_ITSELF
+          + 5 // level 3
+      );
+      assertThat(picoContainer.getParent().getParent().getComponentAdapters()).hasSize(
         CONTAINER_ITSELF
-          + 72 // level 4
-          + 4 // content of CeConfigurationModule
-          + 4 // content of CeQueueModule
-          + 4 // content of CeHttpModule
-          + 3 // content of CeTaskCommonsModule
-          + 4 // content of ProjectAnalysisTaskModule
-          + 5 // content of CeTaskProcessorModule
-          + 3 // CeCleaningModule + its content
-          + 1 // CeDistributedInformation
-    );
-    assertThat(picoContainer.getParent().getComponentAdapters()).hasSize(
-      CONTAINER_ITSELF
-        + 5 // level 3
-    );
-    assertThat(picoContainer.getParent().getParent().getComponentAdapters()).hasSize(
-      CONTAINER_ITSELF
-        + 12 // MigrationConfigurationModule
-        + 17 // level 2
-    );
-    assertThat(picoContainer.getParent().getParent().getParent().getComponentAdapters()).hasSize(
-      COMPONENTS_IN_LEVEL_1_AT_CONSTRUCTION
-        + 25 // level 1
-        + 47 // content of DaoModule
-        + 3 // content of EsSearchModule
-        + 61 // content of CorePropertyDefinitions
-        + 1 // StopFlagContainer
-    );
-    assertThat(
-      picoContainer.getComponentAdapters().stream()
-        .map(ComponentAdapter::getComponentImplementation)
-        .collect(Collectors.toList())).doesNotContain((Class) HazelcastClientWrapperImpl.class,
-          (Class) CeDistributedInformationImpl.class).contains(
-            (Class) StandaloneCeDistributedInformation.class);
-    assertThat(picoContainer.getParent().getParent().getParent().getParent()).isNull();
-    underTest.stop();
+          + 12 // MigrationConfigurationModule
+          + 17 // level 2
+      );
+      assertThat(picoContainer.getParent().getParent().getParent().getComponentAdapters()).hasSize(
+        COMPONENTS_IN_LEVEL_1_AT_CONSTRUCTION
+          + 25 // level 1
+          + 47 // content of DaoModule
+          + 3 // content of EsSearchModule
+          + 61 // content of CorePropertyDefinitions
+          + 1 // StopFlagContainer
+      );
+      assertThat(
+        picoContainer.getComponentAdapters().stream()
+          .map(ComponentAdapter::getComponentImplementation)
+          .collect(Collectors.toList())).doesNotContain((Class) HazelcastClientWrapperImpl.class,
+            (Class) CeDistributedInformationImpl.class).contains(
+              (Class) StandaloneCeDistributedInformation.class);
+      assertThat(picoContainer.getParent().getParent().getParent().getParent()).isNull();
+    } finally {
+      underTest.stop();
+    }
 
     assertThat(picoContainer.getLifecycleState().isStarted()).isFalse();
     assertThat(picoContainer.getLifecycleState().isStopped()).isFalse();