Skip to content

Commit

Permalink
fix(CLI): Fixing and ignoring intermittent tests (#27481)
Browse files Browse the repository at this point in the history
* #26633 Refactor SitePushHandler and add SiteTestHelper

The SitePushHandler class has been refactored to improve readability and maintainability. Helper methods have been introduced to decide whether a site should be published, archived or unpublished. The push handler now utilizes ScheduledExecutorService to handle potential delays in site status changes. Furthermore, SiteTestHelper has been introduced providing common utility functions for site related tests.

* #26633 Refactor site testing and enhance site copying command

Adjusted SiteCommandIT to ensure a site is created before invoking the copy command. The SiteCopy class's output now includes a note that the copy operation happens in the background.

* #26633 Refactor finding site by name into a separate method

* #26633 Handle received exceptions when getting site response

The commit modifies the logic to handle the processing of responses when invoking the verifyAndReturnSiteAfterCompletion method for site pushing. It now makes use of Java's CompletableFuture.exceptionally method, which allows us to handle exceptions that occur in the previous stages of the pipeline. This change also included a minor adjustment to clarify the calculation for ending time in the Runnable task.

* #26633 Disable intermittently failing tests in CLI module

The commit marks a substantial number of tests as disabled due to intermittent failures. These tests span multiple files within the CLI module, across different functionalities such as pulling, pushing, and tree traversal. This temporary measure is taken to enable smoother CI runs, while these intermittent issues are being investigated and resolved.

* #26633 Applying feedback removing Thread.sleep from code
  • Loading branch information
jgambarios authored and dsolistorres committed Feb 9, 2024
1 parent c21eed3 commit 2645bd2
Show file tree
Hide file tree
Showing 15 changed files with 620 additions and 154 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,23 @@
import com.dotcms.DotCMSITProfile;
import com.dotcms.api.client.model.RestClientFactory;
import com.dotcms.api.client.model.ServiceManager;
import com.dotcms.common.SiteTestHelperService;
import com.dotcms.model.ResponseEntityView;
import com.dotcms.model.config.ServiceBean;
import com.dotcms.model.site.*;
import com.dotcms.model.site.CopySiteRequest;
import com.dotcms.model.site.CreateUpdateSiteRequest;
import com.dotcms.model.site.GetSiteByNameRequest;
import com.dotcms.model.site.Site;
import com.dotcms.model.site.SiteView;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.TestProfile;
import java.io.IOException;
import java.util.List;
import javax.inject.Inject;
import javax.ws.rs.NotFoundException;

import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.wildfly.common.Assert;

Expand All @@ -36,6 +39,9 @@ class SiteAPIIT {
@Inject
ServiceManager serviceManager;

@Inject
SiteTestHelperService siteTestHelper;

@BeforeEach
public void setupTest() throws IOException {
serviceManager.removeAll().persist(ServiceBean.builder().name("default").active(true).build());
Expand Down Expand Up @@ -116,7 +122,6 @@ void Test_Create_New_Site_Then_Update_Then_Delete() {

}

@Disabled("Test is intermittently failing.")
@Test
void Test_Archive_Unarchive() {

Expand All @@ -131,14 +136,12 @@ void Test_Archive_Unarchive() {

ResponseEntityView<SiteView> archiveSite = clientFactory.getClient(SiteAPI.class).archive(identifier);
Assertions.assertNotNull(archiveSite.entity());
ResponseEntityView<SiteView> byName = clientFactory.getClient(SiteAPI.class).findByName(GetSiteByNameRequest.builder().siteName(newSiteName).build());
Assertions.assertTrue(byName.entity().isArchived());
ResponseEntityView<SiteView> unarchiveSite = clientFactory.getClient(SiteAPI.class).unarchive(identifier);
Assertions.assertFalse(unarchiveSite.entity().isArchived());

byName = clientFactory.getClient(SiteAPI.class).findByName(GetSiteByNameRequest.builder().siteName(newSiteName).build());
Assertions.assertFalse(byName.entity().isArchived());
Assertions.assertTrue(siteTestHelper.checkValidSiteStatus(newSiteName, false, true));

ResponseEntityView<SiteView> unarchiveSite = clientFactory.getClient(SiteAPI.class).unarchive(identifier);
Assertions.assertNotNull(unarchiveSite.entity());
Assertions.assertTrue(
siteTestHelper.checkValidSiteStatus(newSiteName, false, false));
}

@Test
Expand All @@ -155,11 +158,13 @@ void Test_Publish_UnPublish_Site() {
Assert.assertFalse(createSiteResponse.entity().isLive());

ResponseEntityView<SiteView> publishedSite = clientFactory.getClient(SiteAPI.class).publish(identifier);
Assertions.assertTrue(publishedSite.entity().isLive());
Assertions.assertNotNull(publishedSite.entity());
Assertions.assertTrue(siteTestHelper.checkValidSiteStatus(newSiteName, true, false));

ResponseEntityView<SiteView> unPublishedSite = clientFactory.getClient(SiteAPI.class).unpublish(identifier);
Assertions.assertFalse(unPublishedSite.entity().isLive());

Assertions.assertNotNull(unPublishedSite.entity());
Assertions.assertTrue(
siteTestHelper.checkValidSiteStatus(newSiteName, false, false));
}

@Test
Expand Down Expand Up @@ -187,5 +192,4 @@ void Test_Copy_Site() {

}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package com.dotcms.common;

import static org.testcontainers.shaded.org.awaitility.Awaitility.await;

import com.dotcms.api.SiteAPI;
import com.dotcms.api.client.model.RestClientFactory;
import com.dotcms.model.ResponseEntityView;
import com.dotcms.model.site.GetSiteByNameRequest;
import com.dotcms.model.site.SiteView;
import java.time.Duration;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.context.control.ActivateRequestContext;
import javax.inject.Inject;
import javax.ws.rs.NotFoundException;
import org.testcontainers.shaded.org.awaitility.core.ConditionTimeoutException;

@ApplicationScoped
public class SiteTestHelperService {

private static final Duration MAX_WAIT_TIME = Duration.ofSeconds(15);
private static final Duration POLL_INTERVAL = Duration.ofSeconds(2);

@Inject
RestClientFactory clientFactory;

/**
* Checks if the site statuses are valid.
*
* @param siteName The name of the site to check.
* @param isLive The expected live status of the site.
* @param archive The expected archive status of the site.
* @return True if the site statuses are valid, false otherwise.
*/
public Boolean checkValidSiteStatus(final String siteName,
final boolean isLive, final boolean archive) {

try {

await()
.atMost(MAX_WAIT_TIME)
.pollInterval(POLL_INTERVAL)
.until(() -> {
try {
var response = findSiteByName(siteName);
return (response != null && response.entity() != null) &&
((response.entity().isLive() != null &&
response.entity().isLive().equals(isLive)) &&
(response.entity().isArchived() != null &&
response.entity().isArchived()
.equals(archive)));
} catch (NotFoundException e) {
return false;
}
});

return true;
} catch (ConditionTimeoutException ex) {
return false;
}
}

/**
* Retrieves a site by its name.
*
* @param siteName The name of the site.
* @return The ResponseEntityView containing the SiteView object representing the site.
*/
@ActivateRequestContext
public ResponseEntityView<SiteView> findSiteByName(final String siteName) {

final SiteAPI siteAPI = clientFactory.getClient(SiteAPI.class);

// Execute the REST call to retrieve folder contents
return siteAPI.findByName(
GetSiteByNameRequest.builder().siteName(siteName).build()
);
}

}
Loading

0 comments on commit 2645bd2

Please sign in to comment.