Fix pipeline intermittent failures

This commit is contained in:
Sara Aspery
2023-01-11 11:59:37 +00:00
parent 69832bd140
commit 3dc637df12
2 changed files with 48 additions and 31 deletions

View File

@@ -2,7 +2,7 @@
* #%L * #%L
* Alfresco Search Services E2E Test * Alfresco Search Services E2E Test
* %% * %%
* Copyright (C) 2005 - 2020 Alfresco Software Limited * Copyright (C) 2005 - 2022 Alfresco Software Limited
* %% * %%
* This file is part of the Alfresco software. * This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of * If the software was purchased under a paid Alfresco license, the terms of
@@ -43,6 +43,7 @@ import org.alfresco.dataprep.ContentService;
import org.alfresco.dataprep.SiteService.Visibility; import org.alfresco.dataprep.SiteService.Visibility;
import org.alfresco.rest.core.RestProperties; import org.alfresco.rest.core.RestProperties;
import org.alfresco.rest.core.RestWrapper; import org.alfresco.rest.core.RestWrapper;
import org.alfresco.rest.exception.EmptyJsonResponseException;
import org.alfresco.rest.exception.EmptyRestModelCollectionException; import org.alfresco.rest.exception.EmptyRestModelCollectionException;
import org.alfresco.rest.model.RestRequestSpellcheckModel; import org.alfresco.rest.model.RestRequestSpellcheckModel;
import org.alfresco.rest.search.Pagination; import org.alfresco.rest.search.Pagination;
@@ -302,23 +303,30 @@ public abstract class AbstractE2EFunctionalTest extends AbstractTestNGSpringCont
// Repeat search until the query results are as expected or Search Retry count is hit // Repeat search until the query results are as expected or Search Retry count is hit
for (int searchCount = 0; searchCount < SEARCH_MAX_ATTEMPTS; searchCount++) for (int searchCount = 0; searchCount < SEARCH_MAX_ATTEMPTS; searchCount++)
{ {
SearchResponse response = query(searchRequest); try
if (restClient.getStatusCode().matches(expectedStatusCode))
{ {
boolean found = isContentInSearchResponse(response, contentName); SearchResponse response = query(searchRequest);
// Exit loop if result is as expected. if (restClient.getStatusCode().matches(expectedStatusCode))
if (expectedInResults == found)
{ {
return true; boolean found = isContentInSearchResponse(response, contentName);
// Exit loop if result is as expected.
if (expectedInResults == found)
{
return true;
}
// Wait for the solr indexing (eventual consistency).
Utility.waitToLoopTime(properties.getSolrWaitTimeInSeconds(), "Wait For Indexing. Retry Attempt: " + (searchCount + 1));
}
else
{
throw new RuntimeException("API returned status code:" + restClient.getStatusCode() + " Expected: " + expectedStatusCode + "; Response body: " + response);
} }
// Wait for the solr indexing (eventual consistency).
Utility.waitToLoopTime(properties.getSolrWaitTimeInSeconds(), "Wait For Indexing. Retry Attempt: " + (searchCount + 1));
} }
else catch (EmptyJsonResponseException e)
{ {
throw new RuntimeException("API returned status code:" + restClient.getStatusCode() + " Expected: " + expectedStatusCode + "; Response body: " + response); // Ignore the empty JSON response and try again
} }
} }

View File

@@ -25,6 +25,7 @@ package org.alfresco.test.search.functional.searchServices.search;
import org.alfresco.rest.search.RestRequestQueryModel; import org.alfresco.rest.search.RestRequestQueryModel;
import org.alfresco.rest.search.SearchRequest; import org.alfresco.rest.search.SearchRequest;
import org.alfresco.rest.search.SearchResponse; import org.alfresco.rest.search.SearchResponse;
import org.alfresco.utility.Utility;
import org.alfresco.utility.model.FileModel; import org.alfresco.utility.model.FileModel;
import org.alfresco.utility.model.FileType; import org.alfresco.utility.model.FileType;
import org.hamcrest.Matchers; import org.hamcrest.Matchers;
@@ -235,10 +236,18 @@ public class SearchSimpleCasesTest extends AbstractSearchServicesE2ETest
SearchRequest searchReq = createQuery("name:'" + specialCharfileName + "'"); SearchRequest searchReq = createQuery("name:'" + specialCharfileName + "'");
SearchResponse nodes = query(searchReq); SearchResponse nodes = query(searchReq);
restClient.assertStatusCodeIs(HttpStatus.OK); restClient.assertStatusCodeIs(HttpStatus.OK);
nodes.assertThat().entriesListIsNotEmpty();
int searchCount = 0;
while (nodes.isEmpty() && searchCount < SEARCH_MAX_ATTEMPTS)
{
// Wait for the solr indexing (eventual consistency).
Utility.waitToLoopTime(properties.getSolrWaitTimeInSeconds(), "Wait For Results After Indexing. Retry Attempt: " + (searchCount + 1));
nodes = query(searchReq);
restClient.assertStatusCodeIs(HttpStatus.OK);
}
nodes.assertThat().entriesListIsNotEmpty();
restClient.onResponse().assertThat().body("list.entries.entry[0].name", Matchers.equalToIgnoringCase(specialCharfileName)); restClient.onResponse().assertThat().body("list.entries.entry[0].name", Matchers.equalToIgnoringCase(specialCharfileName));
} }
} }