]> source.dussan.org Git - sonarqube.git/commitdiff
NO-JIRA - Improve flaky tests
authorAntoine Vinot <antoine.vinot@sonarsource.com>
Wed, 7 Jun 2023 15:40:43 +0000 (17:40 +0200)
committersonartech <sonartech@sonarsource.com>
Mon, 12 Jun 2023 20:02:49 +0000 (20:02 +0000)
server/sonar-server-common/src/testFixtures/java/org/sonar/server/es/EsTester.java

index 5b304813d719071bfafb44c64a12eb52618cf9f4..ca3cbb50ca8893a5f992a666c8136168c80adb63 100644 (file)
@@ -103,6 +103,7 @@ import static com.google.common.base.Preconditions.checkState;
 import static com.google.common.collect.Lists.newArrayList;
 import static java.lang.String.format;
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.fail;
 import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
 import static org.sonar.server.es.Index.ALL_INDICES;
 import static org.sonar.server.es.IndexType.FIELD_INDEX_TYPE;
@@ -230,18 +231,14 @@ public class EsTester extends ExternalResource {
   }
 
   public void putDocuments(IndexType indexType, BaseDoc... docs) {
-    try {
-      BulkRequest bulk = new BulkRequest()
-        .setRefreshPolicy(REFRESH_IMMEDIATE);
-      for (BaseDoc doc : docs) {
-        bulk.add(doc.toIndexRequest());
-      }
-      BulkResponse bulkResponse = ES_REST_CLIENT.bulk(bulk);
-      if (bulkResponse.hasFailures()) {
-        throw new IllegalStateException(bulkResponse.buildFailureMessage());
-      }
-    } catch (Exception e) {
-      throw Throwables.propagate(e);
+    BulkRequest bulk = new BulkRequest()
+      .setRefreshPolicy(REFRESH_IMMEDIATE);
+    for (BaseDoc doc : docs) {
+      bulk.add(doc.toIndexRequest());
+    }
+    BulkResponse bulkResponse = ES_REST_CLIENT.bulk(bulk);
+    if (bulkResponse.hasFailures()) {
+      fail("Bulk indexing of documents failed: " + bulkResponse.buildFailureMessage());
     }
   }