-
Notifications
You must be signed in to change notification settings - Fork 470
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(CLI): Fixing and ignoring intermittent tests (#27481)
* #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
1 parent
48df234
commit c4e5541
Showing
15 changed files
with
620 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
tools/dotcms-cli/api-data-model/src/test/java/com/dotcms/common/SiteTestHelperService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
); | ||
} | ||
|
||
} |
Oops, something went wrong.