From 541e5824d2c81c40fd1eb439b68df5e1642e1b1f Mon Sep 17 00:00:00 2001 From: Prajwol Amatya <83579989+PrajwolAmatya@users.noreply.github.com> Date: Thu, 20 Aug 2026 11:14:14 +0545 Subject: [PATCH] [tests-only][full-ci] add retry logic for space creation and copy request (#12815) * test: add retry once for space creation wherever required (#12785) Signed-off-by: nabim777 * test: add retry logic for file copy requests (#12781) Signed-off-by: nabim777 --------- Signed-off-by: nabim777 Co-authored-by: Nalem7 <61624650+nabim777@users.noreply.github.com> --- tests/acceptance/bootstrap/SpacesContext.php | 29 +++++++++++++++++-- .../features/apiCollaboration/wopi.feature | 2 +- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/tests/acceptance/bootstrap/SpacesContext.php b/tests/acceptance/bootstrap/SpacesContext.php index e031be5e030..57ee5a57a84 100644 --- a/tests/acceptance/bootstrap/SpacesContext.php +++ b/tests/acceptance/bootstrap/SpacesContext.php @@ -1902,11 +1902,12 @@ class SpacesContext implements Context { } /** - * @Given /^user "([^"]*)" has created a space "([^"]*)"(| in vault)? with the default quota using the Graph API$/ + * @Given /^user "([^"]*)" has created a space "([^"]*)"(| in vault)?(| with retry) with the default quota using the Graph API$/ * * @param string $user * @param string $spaceName * @param string $isVault + * @param string $withRetry * * @return void * @@ -1917,10 +1918,22 @@ class SpacesContext implements Context { string $user, string $spaceName, string $isVault, + string $withRetry, ): void { $space = ["name" => $spaceName]; $isVault = trim($isVault) === "in vault"; + $withRetry = trim($withRetry) === "with retry"; + + // The user role may take some time to update + // This can cause an unauthorized error + // Retry once after 1 second $response = $this->createSpace($user, $space, $isVault); + + if ($withRetry && $response->getStatusCode() === 401) { + sleep(1); // Wait 1 second before retrying. + $response = $this->createSpace($user, $space, $isVault); + } + $this->featureContext->theHTTPStatusCodeShouldBe( 201, "Expected response status code should be 201 (Created)", @@ -2561,7 +2574,19 @@ class SpacesContext implements Context { } $fullUrl = "$baseUrl/$sourceDavPath/$fileId"; if ($actionType === 'copied') { - $response = $this->copyFilesAndFoldersRequest($user, $fullUrl, $headers); + // while performing copy operation, + // sometime it will return 500 error. + // So we need to retry the copy operation. + $maxAttempts = 3; + for ($attempt = 1; $attempt <= $maxAttempts; $attempt++) { + $response = $this->copyFilesAndFoldersRequest($user, $fullUrl, $headers); + if ($response->getStatusCode() !== 500) { + break; + } + if ($attempt < $maxAttempts) { + \sleep(1); + } + } } else { $response = $this->moveFilesAndFoldersRequest($user, $fullUrl, $headers); } diff --git a/tests/acceptance/features/apiCollaboration/wopi.feature b/tests/acceptance/features/apiCollaboration/wopi.feature index 4170951de8b..860fe81f4e3 100644 --- a/tests/acceptance/features/apiCollaboration/wopi.feature +++ b/tests/acceptance/features/apiCollaboration/wopi.feature @@ -834,7 +834,7 @@ Feature: collaboration (wopi) Scenario: user with Viewer role tries to create a odt file inside shared project space using wopi endpoint Given using spaces DAV path And the administrator has assigned the role "Space Admin" to user "Alice" using the Graph API - And user "Alice" has created a space "new-space" with the default quota using the Graph API + And user "Alice" has created a space "new-space" with retry with the default quota using the Graph API And user "Alice" has created a folder "testFolder" in space "new-space" And user "Alice" has sent the following space share invitation: | space | new-space |