Skip to content

Commit

Permalink
Merge pull request #32781 from owncloud/create-local_storage-files-on…
Browse files Browse the repository at this point in the history
…-server

Create local_storage files on the server
  • Loading branch information
phil-davis committed Sep 20, 2018
2 parents 5990139 + db4608a commit f2bf7fa
Show file tree
Hide file tree
Showing 24 changed files with 108 additions and 93 deletions.
2 changes: 1 addition & 1 deletion tests/acceptance/features/apiMain/checksums.feature
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ Feature: checksums
Scenario Outline: Downloading a file from local storage has correct checksum
Given using <dav_version> DAV path
# Create the file directly in local storage, bypassing ownCloud
And file "prueba_cksum.txt" with text "Test file for checksums" has been created in local storage
And file "prueba_cksum.txt" with text "Test file for checksums" has been created in local storage on the server
# Do a first download, which will trigger ownCloud to calculate a checksum for the file
When user "user0" downloads the file "/local_storage/prueba_cksum.txt" using the WebDAV API
# Now do a download that is expected to have a checksum with it
Expand Down
35 changes: 16 additions & 19 deletions tests/acceptance/features/bootstrap/BasicStructure.php
Original file line number Diff line number Diff line change
Expand Up @@ -1098,12 +1098,15 @@ public static function removeFile($path, $filename) {
}

/**
* Creates a file locally in the file system of the test runner
* The file will be available to upload to the server
*
* @param string $name
* @param string $size
*
* @return void
*/
public function createFileSpecificSize($name, $size) {
public function createLocalFileOfSpecificSize($name, $size) {
$file = \fopen($this->workStorageDirLocation() . $name, 'w');
\fseek($file, $size - 1, SEEK_CUR);
\fwrite($file, 'a'); // write a dummy char at SIZE position
Expand All @@ -1116,34 +1119,28 @@ public function createFileSpecificSize($name, $size) {
*
* @return void
*/
public function createFileWithText($name, $text) {
$file = \fopen($this->workStorageDirLocation() . $name, 'w');
\fwrite($file, $text);
\fclose($file);
}

/**
* @Given file :filename of size :size has been created in local storage
*
* @param string $filename
* @param string $size
*
* @return void
*/
public function fileHasBeenCreatedInLocalStorageWithSize($filename, $size) {
$this->createFileSpecificSize("local_storage/$filename", $size);
public function createFileOnServerWithText($name, $text) {
SetupHelper::createFileOnServer(
$this->getBaseUrl(),
$this->getAdminUsername(),
$this->getAdminPassword(),
$name,
$text
);
}

/**
* @Given file :filename with text :text has been created in local storage
* @Given file :filename with text :text has been created in local storage on the server
*
* @param string $filename
* @param string $text
*
* @return void
*/
public function fileHasBeenCreatedInLocalStorageWithText($filename, $text) {
$this->createFileWithText("local_storage/$filename", $text);
$this->createFileOnServerWithText(
LOCAL_STORAGE_DIR_ON_REMOTE_SERVER . "/$filename", $text
);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/acceptance/features/bootstrap/WebDav.php
Original file line number Diff line number Diff line change
Expand Up @@ -1682,7 +1682,7 @@ public function filesUploadedToWithAllMechanismsShouldExist(
*/
public function userAddsAFileTo($user, $destination, $bytes) {
$filename = "filespecificSize.txt";
$this->createFileSpecificSize($filename, $bytes);
$this->createLocalFileOfSpecificSize($filename, $bytes);
PHPUnit_Framework_Assert::assertFileExists($this->workStorageDirLocation() . $filename);
$this->userUploadsAFileTo(
$user,
Expand Down
14 changes: 7 additions & 7 deletions tests/acceptance/features/bootstrap/WebUIFilesContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ public function deleteTheFileUsingTheWebUI($name, $expectToDeleteFile = true) {
// We do not expect to be able to delete the file,
// so do not waste time doing too many retries.
$pageObject->deleteFile(
$name, $session, $expectToDeleteFile, MINIMUMRETRYCOUNT
$name, $session, $expectToDeleteFile, MINIMUM_RETRY_COUNT
);
}
}
Expand Down Expand Up @@ -598,7 +598,7 @@ public function theFollowingFilesFoldersHaveBeenDeleted(TableNode $filesTable) {
foreach ($filesTable as $file) {
$username = $this->featureContext->getCurrentUser();
$currentTime = \microtime(true);
$end = $currentTime + (LONGUIWAITTIMEOUTMILLISEC / 1000);
$end = $currentTime + (LONG_UI_WAIT_TIMEOUT_MILLISEC / 1000);
//retry deleting in case the file is locked (code 403)
while ($currentTime <= $end) {
$response = DeleteHelper::delete(
Expand All @@ -623,7 +623,7 @@ public function theFollowingFilesFoldersHaveBeenDeleted(TableNode $filesTable) {
);
}

\usleep(STANDARDSLEEPTIMEMICROSEC);
\usleep(STANDARD_SLEEP_TIME_MICROSEC);
$currentTime = \microtime(true);
}

Expand Down Expand Up @@ -740,7 +740,7 @@ public function theUserUploadsOverwritingTheFileUsingTheWebUIRetry($name) {
$previousNotificationsCount = 0;

for ($retryCounter = 0;
$retryCounter < STANDARDRETRYCOUNT;
$retryCounter < STANDARD_RETRY_COUNT;
$retryCounter++) {
$this->theUserUploadsOverwritingTheFileUsingTheWebUI($name);

Expand All @@ -761,7 +761,7 @@ public function theUserUploadsOverwritingTheFileUsingTheWebUIRetry($name) {
echo $message;
\error_log($message);
$previousNotificationsCount = $currentNotificationsCount;
\usleep(STANDARDSLEEPTIMEMICROSEC);
\usleep(STANDARD_SLEEP_TIME_MICROSEC);
} else {
break;
}
Expand Down Expand Up @@ -1384,7 +1384,7 @@ public function theFilesActionMenuShouldBeCompletelyVisibleAfterOpeningItUsingTh
for ($i = 1; $i <= $this->filesPage->getSizeOfFileFolderList(); $i++) {
$actionMenu = $this->filesPage->openFileActionsMenuByNo($i);

$timeout_msec = STANDARDUIWAITTIMEOUTMILLISEC;
$timeout_msec = STANDARD_UI_WAIT_TIMEOUT_MILLISEC;
$currentTime = \microtime(true);
$end = $currentTime + ($timeout_msec / 1000);
while ($currentTime <= $end) {
Expand All @@ -1401,7 +1401,7 @@ public function theFilesActionMenuShouldBeCompletelyVisibleAfterOpeningItUsingTh
if ($windowHeight >= $deleteBtnCoordinates ["top"]) {
break;
}
\usleep(STANDARDSLEEPTIMEMICROSEC);
\usleep(STANDARD_SLEEP_TIME_MICROSEC);
$currentTime = \microtime(true);
}

Expand Down
4 changes: 2 additions & 2 deletions tests/acceptance/features/bootstrap/WebUIGeneralContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -349,9 +349,9 @@ public function dialogsShouldBeDisplayedOnTheWebUI(
$count = (int) $count;
}
$currentTime = \microtime(true);
$end = $currentTime + (STANDARDUIWAITTIMEOUTMILLISEC / 1000);
$end = $currentTime + (STANDARD_UI_WAIT_TIMEOUT_MILLISEC / 1000);
while ($currentTime <= $end && ($count !== \count($dialogs))) {
\usleep(STANDARDSLEEPTIMEMICROSEC);
\usleep(STANDARD_SLEEP_TIME_MICROSEC);
$currentTime = \microtime(true);
$dialogs = $this->owncloudPage->getOcDialogs();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ private function addToListOfCreatedPublicLinks($name, $url) {
* @throws \Exception
*/
public function theUserSharesTheFileFolderWithTheUserUsingTheWebUI(
$folder, $remote, $user, $maxRetries = STANDARDRETRYCOUNT, $quiet = false
$folder, $remote, $user, $maxRetries = STANDARD_RETRY_COUNT, $quiet = false
) {
$this->filesPage->waitTillPageIsloaded($this->getSession());
try {
Expand Down
34 changes: 26 additions & 8 deletions tests/acceptance/features/bootstrap/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,36 @@
$classLoader->register();

// Sleep for 10 milliseconds
const STANDARDSLEEPTIMEMILLISEC = 10;
const STANDARDSLEEPTIMEMICROSEC = STANDARDSLEEPTIMEMILLISEC * 1000;
const STANDARD_SLEEP_TIME_MILLISEC = 10;
const STANDARD_SLEEP_TIME_MICROSEC = STANDARD_SLEEP_TIME_MILLISEC * 1000;

// Long timeout for use in code that needs to wait for known slow UI
const LONGUIWAITTIMEOUTMILLISEC = 60000;
const LONG_UI_WAIT_TIMEOUT_MILLISEC = 60000;
// Default timeout for use in code that needs to wait for the UI
const STANDARDUIWAITTIMEOUTMILLISEC = 10000;
const STANDARD_UI_WAIT_TIMEOUT_MILLISEC = 10000;
// Minimum timeout for use in code that needs to wait for the UI
const MINIMUMUIWAITTIMEOUTMILLISEC = 500;
const MINIMUMUIWAITTIMEOUTMICROSEC = MINIMUMUIWAITTIMEOUTMILLISEC * 1000;
const MINIMUM_UI_WAIT_TIMEOUT_MILLISEC = 500;
const MINIMUM_UI_WAIT_TIMEOUT_MICROSEC = MINIMUM_UI_WAIT_TIMEOUT_MILLISEC * 1000;

// Default number of times to retry where retries are useful
const STANDARDRETRYCOUNT = 5;
const STANDARD_RETRY_COUNT = 5;
// Minimum number of times to retry where retries are useful
const MINIMUMRETRYCOUNT = 2;
const MINIMUM_RETRY_COUNT = 2;

// The remote server-under-test might or might not happen to have this directory.
// If it does not exist, then the tests may end up creating it.
const ACCEPTANCE_TEST_DIR_ON_REMOTE_SERVER = "tests/acceptance";

// The following directory should NOT already exist on the remote server-under-test.
// Acceptance tests are free to do anything needed in this directory, and to
// delete it during or at the end of testing.
const TEMPORARY_STORAGE_DIR_ON_REMOTE_SERVER = ACCEPTANCE_TEST_DIR_ON_REMOTE_SERVER . "/work";

// The following directory is created, used, and deleted by tests that need to
// use some "local external storage" on the server.
const LOCAL_STORAGE_DIR_ON_REMOTE_SERVER = TEMPORARY_STORAGE_DIR_ON_REMOTE_SERVER . "/local_storage";

// Deprecated forms of constants
// ToDo: remove these after app acceptance tests have been adjusted
const STANDARDSLEEPTIMEMICROSEC = STANDARD_SLEEP_TIME_MILLISEC * 1000;
const STANDARDUIWAITTIMEOUTMILLISEC = 10000;
4 changes: 2 additions & 2 deletions tests/acceptance/features/lib/AdminAppsSettingsPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,13 @@ public function enableApp($appName) {
*/
public function waitForAjaxCallsToStartAndFinish(
Session $session,
$timeout_msec = STANDARDUIWAITTIMEOUTMILLISEC
$timeout_msec = STANDARD_UI_WAIT_TIMEOUT_MILLISEC
) {
$start = \microtime(true);
$this->waitForAjaxCallsToStart($session);
$end = \microtime(true);
$timeout_msec = $timeout_msec - (($end - $start) * 1000);
$timeout_msec = \max($timeout_msec, MINIMUMUIWAITTIMEOUTMILLISEC);
$timeout_msec = \max($timeout_msec, MINIMUM_UI_WAIT_TIMEOUT_MILLISEC);
$this->waitForOutstandingAjaxCalls($session, $timeout_msec);
}
}
4 changes: 2 additions & 2 deletions tests/acceptance/features/lib/AdminSharingSettingsPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,13 +276,13 @@ public function toggleRestrictUsersToOnlyShareWithTheirGroupMembers($action) {
*/
public function waitForAjaxCallsToStartAndFinish(
Session $session,
$timeout_msec = STANDARDUIWAITTIMEOUTMILLISEC
$timeout_msec = STANDARD_UI_WAIT_TIMEOUT_MILLISEC
) {
$start = \microtime(true);
$this->waitForAjaxCallsToStart($session);
$end = \microtime(true);
$timeout_msec = $timeout_msec - (($end - $start) * 1000);
$timeout_msec = \max($timeout_msec, MINIMUMUIWAITTIMEOUTMILLISEC);
$timeout_msec = \max($timeout_msec, MINIMUM_UI_WAIT_TIMEOUT_MILLISEC);
$this->waitForOutstandingAjaxCalls($session, $timeout_msec);
}
}
14 changes: 7 additions & 7 deletions tests/acceptance/features/lib/FilesPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ protected function getFilePathInRowXpath() {
*/
public function createFolder(
Session $session, $name = null,
$timeoutMsec = STANDARDUIWAITTIMEOUTMILLISEC
$timeoutMsec = STANDARD_UI_WAIT_TIMEOUT_MILLISEC
) {
if ($name === null) {
$name = \substr(\str_shuffle($this->strForNormalFileName), 0, 8);
Expand Down Expand Up @@ -165,7 +165,7 @@ public function createFolder(
if ($newFolderButton === null || !$newFolderButton->isVisible()) {
break;
}
\usleep(STANDARDSLEEPTIMEMICROSEC);
\usleep(STANDARD_SLEEP_TIME_MICROSEC);
$currentTime = \microtime(true);
}
while ($currentTime <= $end) {
Expand All @@ -175,7 +175,7 @@ public function createFolder(
} catch (ElementNotFoundException $e) {
//loop around
}
\usleep(STANDARDSLEEPTIMEMICROSEC);
\usleep(STANDARD_SLEEP_TIME_MICROSEC);
$currentTime = \microtime(true);
}

Expand Down Expand Up @@ -283,7 +283,7 @@ public function renameFile(
$fromFileName,
$toFileName,
Session $session,
$maxRetries = STANDARDRETRYCOUNT
$maxRetries = STANDARD_RETRY_COUNT
) {
if (\is_array($toFileName)) {
$toFileName = \implode($toFileName);
Expand Down Expand Up @@ -324,7 +324,7 @@ public function renameFile(
* @return void
*/
public function moveFileTo(
$name, $destination, Session $session, $maxRetries = STANDARDRETRYCOUNT
$name, $destination, Session $session, $maxRetries = STANDARD_RETRY_COUNT
) {
$toMoveFileRow = $this->findFileRowByName($name, $session);
$destinationFileRow = $this->findFileRowByName($destination, $session);
Expand Down Expand Up @@ -447,12 +447,12 @@ public function waitForUploadProgressbarToFinish() {
);
}
$currentTime = \microtime(true);
$end = $currentTime + (STANDARDUIWAITTIMEOUTMILLISEC / 1000);
$end = $currentTime + (STANDARD_UI_WAIT_TIMEOUT_MILLISEC / 1000);
while ($uploadProgressbar->isVisible()) {
if ($currentTime > $end) {
break;
}
\usleep(STANDARDSLEEPTIMEMICROSEC);
\usleep(STANDARD_SLEEP_TIME_MICROSEC);
$currentTime = \microtime(true);
}
}
Expand Down
16 changes: 8 additions & 8 deletions tests/acceptance/features/lib/FilesPageBasic.php
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ public function deleteFile(
$name,
Session $session,
$expectToDeleteFile = true,
$maxRetries = STANDARDRETRYCOUNT
$maxRetries = STANDARD_RETRY_COUNT
) {
$this->initAjaxCounters($session);
$this->resetSumStartedAjaxRequests($session);
Expand Down Expand Up @@ -360,7 +360,7 @@ public function deleteFile(
. "\n-------------------------\n"
);
}
\usleep(STANDARDSLEEPTIMEMICROSEC);
\usleep(STANDARD_SLEEP_TIME_MICROSEC);
}
}
if ($expectToDeleteFile && ($counter > 0)) {
Expand Down Expand Up @@ -542,7 +542,7 @@ public function isFolderEmpty(Session $session) {
*/
public function waitTillPageIsLoaded(
Session $session,
$timeout_msec = LONGUIWAITTIMEOUTMILLISEC
$timeout_msec = LONG_UI_WAIT_TIMEOUT_MILLISEC
) {
$this->initAjaxCounters($session);
$currentTime = \microtime(true);
Expand Down Expand Up @@ -597,7 +597,7 @@ public function waitTillPageIsLoaded(
}
}

\usleep(STANDARDSLEEPTIMEMICROSEC);
\usleep(STANDARD_SLEEP_TIME_MICROSEC);
$currentTime = \microtime(true);
}

Expand All @@ -622,7 +622,7 @@ public function waitTillPageIsLoaded(
*/
public function waitTillFileRowsAreReady(
Session $session,
$timeout_msec = LONGUIWAITTIMEOUTMILLISEC
$timeout_msec = LONG_UI_WAIT_TIMEOUT_MILLISEC
) {
$currentTime = \microtime(true);
$end = $currentTime + ($timeout_msec / 1000);
Expand All @@ -639,7 +639,7 @@ public function waitTillFileRowsAreReady(
}
}

\usleep(STANDARDSLEEPTIMEMICROSEC);
\usleep(STANDARD_SLEEP_TIME_MICROSEC);
$currentTime = \microtime(true);
}

Expand Down Expand Up @@ -672,7 +672,7 @@ public function enableShowHiddenFilesSettings() {
"could not find the appSettings section"
);
}
$timeout_msec = LONGUIWAITTIMEOUTMILLISEC;
$timeout_msec = LONG_UI_WAIT_TIMEOUT_MILLISEC;
$currentTime = \microtime(true);
$end = $currentTime + ($timeout_msec / 1000);
while ($appSettingsDiv->getAttribute('style') !== $this->styleOfCheckboxWhenVisible) {
Expand All @@ -682,7 +682,7 @@ public function enableShowHiddenFilesSettings() {
" timed out waiting for show hidden files checkbox to appear"
);
}
\usleep(STANDARDSLEEPTIMEMICROSEC);
\usleep(STANDARD_SLEEP_TIME_MICROSEC);
$currentTime = \microtime(true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public function closeDetailsDialog() {
*/
public function waitTillPageIsLoaded(
Session $session,
$timeout_msec = STANDARDUIWAITTIMEOUTMILLISEC
$timeout_msec = STANDARD_UI_WAIT_TIMEOUT_MILLISEC
) {
$currentTime = \microtime(true);
$end = $currentTime + ($timeout_msec / 1000);
Expand All @@ -199,7 +199,7 @@ public function waitTillPageIsLoaded(
} catch (ElementNotFoundException $e) {
// Just loop and try again if the element was not found yet.
}
\usleep(STANDARDSLEEPTIMEMICROSEC);
\usleep(STANDARD_SLEEP_TIME_MICROSEC);
$currentTime = \microtime(true);
}

Expand Down
Loading

0 comments on commit f2bf7fa

Please sign in to comment.