Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tests-only] retry if auto-sync is enabled but client.synchronize is false #8891

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Feature: an user gets the resources shared to them
| sharee | Brian |
| shareType | user |
| permissionsRole | Viewer |
When user "Brian" lists the shares shared with him after clearing user cache using the Graph API
When user "Brian" lists the shares shared with him using the Graph API
Then the HTTP status code should be "200"
And the JSON data of the response should match
"""
Expand Down
28 changes: 28 additions & 0 deletions tests/acceptance/features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,34 @@ class FeatureContext extends BehatVariablesContext {
private array $lastHttpStatusCodesArray = [];
private array $lastOCSStatusCodesArray = [];

/**
* Store for auto-sync settings for users
*/
private array $autoSyncSettings = [];

/**
* @param string $user
*
* @return bool
*/
public function getUserAutoSyncSetting(string $user): bool {
if (\array_key_exists($user, $this->autoSyncSettings)) {
return $this->autoSyncSettings[$user];
}
// auto-sync is enabled by default
return true;
}

/**
* @param string $user
* @param bool $value
*
* @return void
*/
public function rememberUserAutoSyncSetting(string $user, bool $value): void {
$this->autoSyncSettings[$user] = $value;
}

/**
* this is set true for db conversion tests
*/
Expand Down
32 changes: 28 additions & 4 deletions tests/acceptance/features/bootstrap/GraphContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -2503,14 +2503,38 @@ public function userListsTheResourcesSharedWithThemUsingGraphApi(string $user, s
}

$credentials = $this->getAdminOrUserCredentials($user);
$this->featureContext->setResponse(
GraphHelper::getSharesSharedWithMe(

// Sometimes listing shares might not return the updated shares list
// so try again until @client.synchronize is true for the max. number of retries (i.e. 10)
// and do not retry when the share is expected to be not synced
$tryAgain = false;
$retried = 0;
do {
$response = GraphHelper::getSharesSharedWithMe(
$this->featureContext->getBaseUrl(),
$this->featureContext->getStepLineRef(),
$credentials['username'],
$credentials['password']
)
);
);

$jsonObj = $this->featureContext->getJsonDecodedResponseBodyContent($response);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$jsonObj = $this->featureContext->getJsonDecodedResponseBodyContent($response);
$jsonObj = $this->featureContext->getJsonDecodedResponseBodyContent($response);

$jsonObj name should be replace with meaningful name


foreach ($jsonObj->value as $share) {
$autoSync = $this->featureContext->getUserAutoSyncSetting($credentials['username']);
$tryAgain = !$share->{'@client.synchronize'} && $autoSync && $retried < HttpRequestHelper::numRetriesOnHttpTooEarly();

if ($tryAgain) {
$retried += 1;
echo "auto-sync share for user '$user' is enabled\n";
echo "but share '$share->name' was not auto-synced, retrying ($retried)...\n";
// wait 500ms and try again
\usleep(500 * 1000);
break;
}
}
} while ($tryAgain);
saw-jan marked this conversation as resolved.
Show resolved Hide resolved

$this->featureContext->setResponse($response);
$this->featureContext->pushToLastStatusCodesArrays();
}

Expand Down
1 change: 1 addition & 0 deletions tests/acceptance/features/bootstrap/SettingsContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -541,5 +541,6 @@ public function theUserHasDisabledAutoAccepting(string $user): void {
"Expected response status code should be 201",
$response
);
$this->featureContext->rememberUserAutoSyncSetting($user, false);
}
}
2 changes: 2 additions & 0 deletions tests/acceptance/features/bootstrap/SharingNgContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -1042,6 +1042,8 @@ public function userDisablesSyncOfShareUsingTheGraphApi(string $user):void {
);
$this->featureContext->setResponse($response);
$this->featureContext->pushToLastStatusCodesArrays();
// disable check for client.synchronize
$this->featureContext->rememberUserAutoSyncSetting($user, false);
}

/**
Expand Down