Skip to content

Commit

Permalink
Retry when doing upload overwrite in UI tests
Browse files Browse the repository at this point in the history
  • Loading branch information
phil-davis committed Feb 18, 2018
1 parent 48c814f commit b5dc81f
Show file tree
Hide file tree
Showing 13 changed files with 85 additions and 28 deletions.
13 changes: 13 additions & 0 deletions tests/ui/features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,19 @@ public function getCurrentPageObject() {
return $this->currentPageObject;
}

/**
* @Then no notification should be displayed
* @return void
*/
public function noNotificationShouldBeDisplayed() {
try {
$notificationText = $this->owncloudPage->getNotificationText();
PHPUnit_Framework_Assert::assertEquals('', $notificationText, "Expecting no notifications but got $notificationText");
} catch (\SensioLabs\Behat\PageObjectExtension\PageObject\Exception\ElementNotFoundException $e) {
// if there is no notification element, then good
}
}

/**
* @Then a notification should be displayed with the text :notificationText
* @param string $notificationText expected notification text
Expand Down
44 changes: 43 additions & 1 deletion tests/ui/features/bootstrap/FilesContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
*/
class FilesContext extends RawMinkContext implements Context {

private $owncloudPage;
private $filesPage;
private $trashbinPage;
private $favoritesPage;
Expand Down Expand Up @@ -91,13 +92,15 @@ class FilesContext extends RawMinkContext implements Context {
* @return void
*/
public function __construct(
OwncloudPage $owncloudPage,
FilesPage $filesPage,
TrashbinPage $trashbinPage,
ConflictDialog $conflictDialog,
FavoritesPage $favoritesPage
) {
$this->trashbinPage = $trashbinPage;
$this->owncloudPage = $owncloudPage;
$this->filesPage = $filesPage;
$this->trashbinPage = $trashbinPage;
$this->conflictDialog = $conflictDialog;
$this->favoritesPage = $favoritesPage;

Expand Down Expand Up @@ -461,6 +464,45 @@ public function iUploadOverwritingTheFile($name) {
$this->iClickTheButton("Continue");
}

/**
* @When I upload overwriting the file :name and retry if the file is locked
* @param string $name
* @return void
*/
public function iUploadOverwritingTheFileRetry($name) {
$previousNotificationsCount = 0;

for ($retryCounter = 0; $retryCounter < STANDARDRETRYCOUNT; $retryCounter++) {
$this->iUploadTheFile($name);
$this->choiceInUploadConflict("new");
$this->iClickTheButton("Continue");

try {
$notifications = $this->owncloudPage->getNotifications();
} catch (\SensioLabs\Behat\PageObjectExtension\PageObject\Exception\ElementNotFoundException $e) {
$notifications = [];
}

$currentNotificationsCount = count($notifications);

if ($currentNotificationsCount > $previousNotificationsCount) {
$message = "Upload overwriting $name and got $currentNotificationsCount notifications including " . end($notifications) . "\n";
echo $message;
error_log($message);
$previousNotificationsCount = $currentNotificationsCount;
usleep(STANDARDSLEEPTIMEMICROSEC);
} else {
break;
}
}

if ($retryCounter > 0) {
$message = "INFORMATION: retried to upload overwriting file $name $retryCounter times";
echo $message;
error_log($message);
}
}

/**
* @When I upload the file :name keeping both new and existing files
* @param string $name
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/features/bootstrap/SharingContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ private function addToListOfCreatedPublicLinks($name, $url) {
* @return void
*/
public function theFileFolderIsSharedWithTheUser(
$folder, $remote, $user, $maxRetries = 5, $quiet = false
$folder, $remote, $user, $maxRetries = STANDARDRETRYCOUNT, $quiet = false
) {
$this->filesPage->waitTillPageIsloaded($this->getSession());
try {
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/features/bootstrap/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,5 @@
const STANDARDUIWAITTIMEOUTMILLISEC = 10000;
// Minimum timeout for use in code that needs to wait for the UI
const MINIMUMUIWAITTIMEOUTMILLISEC = 500;
// Default number of times to retry where retries are useful
const STANDARDRETRYCOUNT = 5;
4 changes: 2 additions & 2 deletions tests/ui/features/lib/FilesPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ public function renameFile(
$fromFileName,
$toFileName,
Session $session,
$maxRetries = 5
$maxRetries = STANDARDRETRYCOUNT
) {
if (is_array($toFileName)) {
$toFileName = implode($toFileName);
Expand Down Expand Up @@ -281,7 +281,7 @@ public function renameFile(
* @return void
*/
public function moveFileTo(
$name, $destination, Session $session, $maxRetries = 5
$name, $destination, Session $session, $maxRetries = STANDARDRETRYCOUNT
) {
$toMoveFileRow = $this->findFileRowByName($name, $session);
$destinationFileRow = $this->findFileRowByName($destination, $session);
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/features/lib/FilesPageBasic.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ public function openFile($name, Session $session) {
* @param int $maxRetries
* @return void
*/
public function deleteFile($name, Session $session, $maxRetries = 5) {
public function deleteFile($name, Session $session, $maxRetries = STANDARDRETRYCOUNT) {
$this->initAjaxCounters($session);
$this->resetSumStartedAjaxRequests($session);

Expand Down
4 changes: 2 additions & 2 deletions tests/ui/features/lib/PublicLinkFilesPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public function renameFile(
$fromFileName,
$toFileName,
Session $session,
$maxRetries = 5
$maxRetries = STANDARDRETRYCOUNT
) {
throw new \Exception("not implemented");
}
Expand All @@ -143,7 +143,7 @@ public function renameFile(
* @return void
*/
public function moveFileTo(
$name, $destination, Session $session, $maxRetries = 5
$name, $destination, Session $session, $maxRetries = STANDARDRETRYCOUNT
) {
throw new \Exception("not implemented");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ So that other users have access to these files
And I relogin with username "user1" and password "1234" to "http://%remote_server%"
And the offered remote shares are accepted
And I open the folder "simple-folder (2)"
And I upload overwriting the file "lorem.txt"
And I upload overwriting the file "lorem.txt" and retry if the file is locked
And I relogin with username "user2" and password "1234" to "%base_url%"
And I open the folder "simple-folder"
Then the file "lorem.txt" should be listed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,6 @@ So that public sharing is limited according to organization policy
When I open the folder "simple-folder (2)"
Then the file "lorem.txt" should be listed
And the content of "lorem.txt" should be the same as the original "simple-folder/lorem.txt"
When I upload overwriting the file "lorem.txt"
When I upload overwriting the file "lorem.txt" and retry if the file is locked
Then the file "lorem.txt" should be listed
And the content of "lorem.txt" should be the same as the local "lorem.txt"
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ So that those groups can access the files and folders
And I relogin with username "user1" and password "1234"
Then the content of "new-lorem.txt" should not be the same as the local "new-lorem.txt"
# overwrite the received shared file
When I upload overwriting the file "new-lorem.txt"
When I upload overwriting the file "new-lorem.txt" and retry if the file is locked
Then the file "new-lorem.txt" should be listed
And the content of "new-lorem.txt" should be the same as the local "new-lorem.txt"
# unshare the received shared file
Expand All @@ -61,7 +61,7 @@ So that those groups can access the files and folders
And I open the folder "new-simple-folder"
Then the content of "lorem.txt" should not be the same as the local "lorem.txt"
# overwrite an existing file in the received share
When I upload overwriting the file "lorem.txt"
When I upload overwriting the file "lorem.txt" and retry if the file is locked
Then the file "lorem.txt" should be listed
And the content of "lorem.txt" should be the same as the local "lorem.txt"
# upload a new file into the received share
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ So that those users can access the files and folders
And I relogin with username "user1" and password "1234"
Then the content of "new-lorem.txt" should not be the same as the local "new-lorem.txt"
# overwrite the received shared file
When I upload overwriting the file "new-lorem.txt"
When I upload overwriting the file "new-lorem.txt" and retry if the file is locked
Then the file "new-lorem.txt" should be listed
And the content of "new-lorem.txt" should be the same as the local "new-lorem.txt"
# unshare the received shared file
Expand All @@ -50,7 +50,7 @@ So that those users can access the files and folders
And I open the folder "new-simple-folder"
Then the content of "lorem.txt" should not be the same as the local "lorem.txt"
# overwrite an existing file in the received share
When I upload overwriting the file "lorem.txt"
When I upload overwriting the file "lorem.txt" and retry if the file is locked
Then the file "lorem.txt" should be listed
And the content of "lorem.txt" should be the same as the local "lorem.txt"
# upload a new file into the received share
Expand Down
24 changes: 12 additions & 12 deletions tests/ui/features/upload/upload.feature
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,33 @@ So that I can store files in ownCloud

Scenario: simple upload of a file that does not exist before
When I upload the file "new-lorem.txt"
Then the file "new-lorem.txt" should be listed
Then no notification should be displayed
And the file "new-lorem.txt" should be listed
And the content of "new-lorem.txt" should be the same as the local "new-lorem.txt"

Scenario: chunking upload
And a file with the size of "30000000" bytes and the name "big-video.mp4" exists
When I upload the file "big-video.mp4"
Then the file "big-video.mp4" should be listed
Then no notification should be displayed
And the file "big-video.mp4" should be listed
And the content of "big-video.mp4" should be the same as the local "big-video.mp4"

Scenario: conflict with a chunked file
And a file with the size of "30000000" bytes and the name "big-video.mp4" exists
When I rename the file "lorem.txt" to "big-video.mp4"
And I upload the file "big-video.mp4"
And I choose to keep the new files
And I click the "Continue" button
And I upload overwriting the file "big-video.mp4" and retry if the file is locked
Then the file "big-video.mp4" should be listed
And the content of "big-video.mp4" should be the same as the local "big-video.mp4"

Scenario: upload a new file into a sub folder
When I open the folder "simple-folder"
And I upload the file "new-lorem.txt"
Then the file "new-lorem.txt" should be listed
Then no notification should be displayed
And the file "new-lorem.txt" should be listed
And the content of "new-lorem.txt" should be the same as the local "new-lorem.txt"

Scenario: overwrite an existing file
When I upload the file "lorem.txt"
And I choose to keep the new files
And I click the "Continue" button
When I upload overwriting the file "lorem.txt" and retry if the file is locked
Then no dialog should be displayed
And the file "lorem.txt" should be listed
And the content of "lorem.txt" should be the same as the local "lorem.txt"
Expand All @@ -53,6 +52,7 @@ So that I can store files in ownCloud
And I choose to keep the existing files
And I click the "Continue" button
Then no dialog should be displayed
And no notification should be displayed
And the file "lorem.txt" should be listed
And the content of "lorem.txt" should not have changed
And the file "lorem (2).txt" should be listed
Expand All @@ -62,15 +62,14 @@ So that I can store files in ownCloud
When I upload the file "lorem.txt"
And I click the "Cancel" button
Then no dialog should be displayed
And no notification should be displayed
And the file "lorem.txt" should be listed
And the content of "lorem.txt" should not have changed
And the file "lorem (2).txt" should not be listed

Scenario: overwrite an existing file in a sub-folder
When I open the folder "simple-folder"
When I upload the file "lorem.txt"
And I choose to keep the new files
And I click the "Continue" button
And I upload overwriting the file "lorem.txt" and retry if the file is locked
Then the file "lorem.txt" should be listed
And the content of "lorem.txt" should be the same as the local "lorem.txt"

Expand All @@ -81,6 +80,7 @@ So that I can store files in ownCloud
And I choose to keep the existing files
And I click the "Continue" button
Then no dialog should be displayed
And no notification should be displayed
And the file "lorem.txt" should be listed
And the content of "lorem.txt" should not have changed
And the file "lorem (2).txt" should be listed
Expand Down
6 changes: 3 additions & 3 deletions tests/ui/features/upload/uploadEdgecases.feature
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ that is not academically correct but saves a lot of time
| "strängé नेपाली folder" |

Scenario: overwrite an existing file
When I upload overwriting the file "'single'quotes.txt"
When I upload overwriting the file "'single'quotes.txt" and retry if the file is locked
Then the file "'single'quotes.txt" should be listed
And the content of "'single'quotes.txt" should be the same as the local "'single'quotes.txt"

When I upload overwriting the file "strängé filename (duplicate #2 &).txt"
When I upload overwriting the file "strängé filename (duplicate #2 &).txt" and retry if the file is locked
Then the file "strängé filename (duplicate #2 &).txt" should be listed
And the content of "strängé filename (duplicate #2 &).txt" should be the same as the local "strängé filename (duplicate #2 &).txt"

When I upload overwriting the file "zzzz-must-be-last-file-in-folder.txt"
When I upload overwriting the file "zzzz-must-be-last-file-in-folder.txt" and retry if the file is locked
Then the file "zzzz-must-be-last-file-in-folder.txt" should be listed
And the content of "zzzz-must-be-last-file-in-folder.txt" should be the same as the local "zzzz-must-be-last-file-in-folder.txt"

Expand Down

0 comments on commit b5dc81f

Please sign in to comment.