From 3476f27c59e75d735cff3bb002e04e6437b76f01 Mon Sep 17 00:00:00 2001 From: Saw-jan Date: Mon, 24 Jun 2024 18:02:40 +0545 Subject: [PATCH 1/5] test: add step to wait until shares are synced --- .../features/bootstrap/SharingNgContext.php | 60 +++++++++++++++++++ .../moveReceivedShare.feature | 1 + 2 files changed, 61 insertions(+) diff --git a/tests/acceptance/features/bootstrap/SharingNgContext.php b/tests/acceptance/features/bootstrap/SharingNgContext.php index f1268ec76a..b1ecee7c27 100644 --- a/tests/acceptance/features/bootstrap/SharingNgContext.php +++ b/tests/acceptance/features/bootstrap/SharingNgContext.php @@ -26,6 +26,7 @@ use Psr\Http\Message\ResponseInterface; use TestHelpers\GraphHelper; use TestHelpers\OcisHelper; use TestHelpers\WebDavHelper; +use TestHelpers\HttpRequestHelper; use Behat\Gherkin\Node\TableNode; use PHPUnit\Framework\Assert; @@ -1240,6 +1241,65 @@ class SharingNgContext implements Context { $this->featureContext->setResponse($response); } + /** + * @param string $user + * @param string $resource + * + * @return void + * @throws GuzzleException + */ + public function isShareSynced(string $user, string $resource): bool { + $resource = \trim($resource, '/'); + $response = GraphHelper::getSharesSharedWithMe( + $this->featureContext->getBaseUrl(), + $this->featureContext->getStepLineRef(), + $user, + $this->featureContext->getPasswordForUser($user) + ); + + $shares = $this->featureContext->getJsonDecodedResponse($response)["value"]; + $syncStatus = false; + foreach ($shares as $share) { + if ($share["name"] === $resource) { + $syncStatus = $share["@client.synchronize"]; + break; + } + } + return $syncStatus === true; + } + + /** + * @Then /^user "([^"]*)" has a share "([^"]*)" synced$/ + * + * @param string $user + * @param string $resource + * + * @return void + * @throws GuzzleException + */ + public function userHasShareSynced(string $user, string $resource): void { + $shareSynced = false; + + // Sharing is async so it might take some time for the share to be available + $retried = 0; + do { + $shareSynced = $this->isShareSynced($user, $resource); + + $tryAgain = !$shareSynced && $retried < HttpRequestHelper::numRetriesOnHttpTooEarly(); + if ($tryAgain) { + $retried += 1; + echo "[INFO] Wait for shares to be available..."; + // wait 500ms and try again + \usleep(500 * 1000); + } + } while ($tryAgain); + + Assert::assertTrue( + $shareSynced, + "Share '$resource' is expected to be synced but not" + ); + } + /** * @Then /^user "([^"]*)" should have sync (enabled|disabled) for share "([^"]*)"$/ * diff --git a/tests/acceptance/features/coreApiShareManagementToShares/moveReceivedShare.feature b/tests/acceptance/features/coreApiShareManagementToShares/moveReceivedShare.feature index 21bd5d8fc0..af64b596e0 100644 --- a/tests/acceptance/features/coreApiShareManagementToShares/moveReceivedShare.feature +++ b/tests/acceptance/features/coreApiShareManagementToShares/moveReceivedShare.feature @@ -180,6 +180,7 @@ Feature: sharing | sharee | grp1 | | shareType | group | | permissionsRole | Viewer | + And user "Carol" has a share "/TMP" synced When user "Carol" moves folder "/Shares/TMP" to "/Shares/new" using the WebDAV API And the administrator deletes user "Carol" using the provisioning API Then the HTTP status code of responses on each endpoint should be "201, 204" respectively From a2fea9bb031409a93c59b1d9ebb062b0e67716e5 Mon Sep 17 00:00:00 2001 From: Saw-jan Date: Mon, 24 Jun 2024 18:18:49 +0545 Subject: [PATCH 2/5] test: fix another test --- .../createShareToSharesFolder.feature | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/acceptance/features/coreApiShareManagementBasicToShares/createShareToSharesFolder.feature b/tests/acceptance/features/coreApiShareManagementBasicToShares/createShareToSharesFolder.feature index b530f7ef0d..63d8cafdcf 100644 --- a/tests/acceptance/features/coreApiShareManagementBasicToShares/createShareToSharesFolder.feature +++ b/tests/acceptance/features/coreApiShareManagementBasicToShares/createShareToSharesFolder.feature @@ -245,7 +245,8 @@ Feature: sharing And user "Brian" has been added to group "grp2" And user "Alice" has created folder "/PARENT" When user "Alice" shares folder "/PARENT" with group "grp1" using the sharing API - Then user "Brian" should see the following elements + Then user "Brian" should have sync enabled for share "PARENT" + And user "Brian" should see the following elements | /Shares/PARENT/ | From 56bd1c175c7644d9f3072b1a4549b5ade0611b2c Mon Sep 17 00:00:00 2001 From: Saw-jan Date: Mon, 24 Jun 2024 18:37:25 +0545 Subject: [PATCH 3/5] test: wait for sync status --- .../features/bootstrap/SharingNgContext.php | 77 ++++++++----------- 1 file changed, 34 insertions(+), 43 deletions(-) diff --git a/tests/acceptance/features/bootstrap/SharingNgContext.php b/tests/acceptance/features/bootstrap/SharingNgContext.php index b1ecee7c27..85e7fff0a2 100644 --- a/tests/acceptance/features/bootstrap/SharingNgContext.php +++ b/tests/acceptance/features/bootstrap/SharingNgContext.php @@ -1268,6 +1268,37 @@ class SharingNgContext implements Context { return $syncStatus === true; } + /** + * @param string $user + * @param string $resource + * @param string $status + * + * @return void + * @throws Exception|GuzzleException + */ + public function waitAndCheckShareSyncStatus(string $user, string $resource, string $status): void { + $expected = $status === "enabled"; + + // NOTE: Sharing is async so it might take some time for the share to be available. + $retried = 0; + do { + $shareSynced = $this->isShareSynced($user, $resource); + + if ($shareSynced === $expected) { + return; + } + + $tryAgain = !$shareSynced && $retried < HttpRequestHelper::numRetriesOnHttpTooEarly(); + if ($tryAgain) { + $retried += 1; + echo "[INFO] Wait for share sync status..."; + // wait 500ms and try again + \usleep(500 * 1000); + } + } while ($tryAgain); + Assert::fail("[Timeout] Sync for share '$resource' was expected to be '$status' but was not"); + } + /** * @Then /^user "([^"]*)" has a share "([^"]*)" synced$/ * @@ -1275,29 +1306,10 @@ class SharingNgContext implements Context { * @param string $resource * * @return void - * @throws GuzzleException + * @throws Exception|GuzzleException */ public function userHasShareSynced(string $user, string $resource): void { - $shareSynced = false; - - // Sharing is async so it might take some time for the share to be available - $retried = 0; - do { - $shareSynced = $this->isShareSynced($user, $resource); - - $tryAgain = !$shareSynced && $retried < HttpRequestHelper::numRetriesOnHttpTooEarly(); - if ($tryAgain) { - $retried += 1; - echo "[INFO] Wait for shares to be available..."; - // wait 500ms and try again - \usleep(500 * 1000); - } - } while ($tryAgain); - - Assert::assertTrue( - $shareSynced, - "Share '$resource' is expected to be synced but not" - ); + $this->waitAndCheckShareSyncStatus($user, $resource, "enabled"); } /** @@ -1311,28 +1323,7 @@ class SharingNgContext implements Context { * @throws GuzzleException */ public function userShouldHaveSyncEnabledOrDisabledForShare(string $user, string $status, string $resource):void { - $response = GraphHelper::getSharesSharedWithMe( - $this->featureContext->getBaseUrl(), - $this->featureContext->getStepLineRef(), - $user, - $this->featureContext->getPasswordForUser($user) - ); - $responseBody = $this->featureContext->getJsonDecodedResponse($response); - $expectedValue = $status === "enabled" ? "true" : "false"; - $actualValue = ""; - foreach ($responseBody["value"] as $value) { - if ($value["remoteItem"]["name"] === $resource) { - // var_export converts values to their string representations - // e.g.: true -> 'true' - $actualValue = var_export($value["@client.synchronize"], true); - break; - } - } - Assert::assertSame( - $actualValue, - $expectedValue, - "Expected property '@client.synchronize' to be '$expectedValue' but found '$actualValue'" - ); + $this->waitAndCheckShareSyncStatus($user, $resource, $status); } /** From e0b6870a728bfa76c939c4b6ff352464ca9e9b83 Mon Sep 17 00:00:00 2001 From: Saw-jan Date: Mon, 24 Jun 2024 18:40:22 +0545 Subject: [PATCH 4/5] test: refactor --- tests/acceptance/features/bootstrap/SharingNgContext.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/acceptance/features/bootstrap/SharingNgContext.php b/tests/acceptance/features/bootstrap/SharingNgContext.php index 85e7fff0a2..dbb79900d0 100644 --- a/tests/acceptance/features/bootstrap/SharingNgContext.php +++ b/tests/acceptance/features/bootstrap/SharingNgContext.php @@ -1265,7 +1265,7 @@ class SharingNgContext implements Context { break; } } - return $syncStatus === true; + return $syncStatus; } /** From 8b6cbb7dc03aad533bf5d38b82d3402f60929c9e Mon Sep 17 00:00:00 2001 From: Saw-jan Date: Mon, 24 Jun 2024 18:42:04 +0545 Subject: [PATCH 5/5] test: refactor --- tests/acceptance/features/bootstrap/SharingNgContext.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/acceptance/features/bootstrap/SharingNgContext.php b/tests/acceptance/features/bootstrap/SharingNgContext.php index dbb79900d0..35ca8439df 100644 --- a/tests/acceptance/features/bootstrap/SharingNgContext.php +++ b/tests/acceptance/features/bootstrap/SharingNgContext.php @@ -1265,6 +1265,7 @@ class SharingNgContext implements Context { break; } } + Assert::assertIsBool($syncStatus, "'@client.synchronize' must be a boolean value"); return $syncStatus; }