Skip to content

Commit

Permalink
Merge pull request #34066 from owncloud/stable10-refactor-upload-dele…
Browse files Browse the repository at this point in the history
…te-sleep

[Stable10] Add pause of one second before delete in acceptance test steps
  • Loading branch information
phil-davis authored Jan 8, 2019
2 parents 6714d4e + 0ed0ef8 commit 58f2eeb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,9 @@ Feature: files and folders exist in the trashbin after being deleted
And user "user0" has created folder "/folderB"
And user "user0" has copied file "/textfile0.txt" to "/folderA/textfile0.txt"
And user "user0" has copied file "/textfile0.txt" to "/folderB/textfile0.txt"
When user "user0" waits and deletes file "/folderA/textfile0.txt" using the WebDAV API
And user "user0" waits and deletes file "/folderB/textfile0.txt" using the WebDAV API
And user "user0" waits and deletes file "/textfile0.txt" using the WebDAV API
When user "user0" deletes file "/folderA/textfile0.txt" using the WebDAV API
And user "user0" deletes file "/folderB/textfile0.txt" using the WebDAV API
And user "user0" deletes file "/textfile0.txt" using the WebDAV API
Then as "user0" the folder with original path "/folderA/textfile0.txt" should exist in trash
And as "user0" the folder with original path "/folderB/textfile0.txt" should exist in trash
And as "user0" the folder with original path "/textfile0.txt" should exist in trash
Expand Down
55 changes: 18 additions & 37 deletions tests/acceptance/features/bootstrap/WebDav.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ trait WebDav {
/**
* @var int
*/
private $lastUploadTime = null;
private $lastUploadDeleteTime = null;

/**
* a variable that contains the dav path without "remote.php/(web)dav"
Expand Down Expand Up @@ -1421,11 +1421,11 @@ public function userUploadsAFileTo($user, $source, $destination) {
'r'
)
);
$this->pauseUpload();
$this->pauseUploadDelete();
$this->response = $this->makeDavRequest(
$user, "PUT", $destination, [], $file
);
$this->lastUploadTime = \time();
$this->lastUploadDeleteTime = \time();
$this->setResponseXml(
HttpRequestHelper::parseResponseAsXml($this->response)
);
Expand Down Expand Up @@ -1484,7 +1484,7 @@ public function uploadFileWithHeaders(
}
try {
$this->responseXml = [];
$this->pauseUpload();
$this->pauseUploadDelete();
$this->response = UploadHelper::upload(
$this->getBaseUrl(),
$this->getActualUsername($user),
Expand All @@ -1496,7 +1496,7 @@ public function uploadFileWithHeaders(
$chunkingVersion,
$noOfChunks
);
$this->lastUploadTime = \time();
$this->lastUploadDeleteTime = \time();
} catch (BadResponseException $e) {
// 4xx and 5xx responses cause an exception
$this->response = $e->getResponse();
Expand Down Expand Up @@ -1824,11 +1824,11 @@ public function userUploadsAFileWithContentTo(
$user, $content, $destination
) {
$file = \GuzzleHttp\Stream\Stream::factory($content);
$this->pauseUpload();
$this->pauseUploadDelete();
$this->response = $this->makeDavRequest(
$user, "PUT", $destination, [], $file
);
$this->lastUploadTime = \time();
$this->lastUploadDeleteTime = \time();
return $this->response->getHeader('oc-fileid');
}

Expand All @@ -1847,15 +1847,15 @@ public function userUploadsAFileWithChecksumAndContentTo(
$user, $checksum, $content, $destination
) {
$file = \GuzzleHttp\Stream\Stream::factory($content);
$this->pauseUpload();
$this->pauseUploadDelete();
$this->response = $this->makeDavRequest(
$user,
"PUT",
$destination,
['OC-Checksum' => $checksum],
$file
);
$this->lastUploadTime = \time();
$this->lastUploadDeleteTime = \time();
}

/**
Expand All @@ -1870,27 +1870,6 @@ public function fileHasBeenDeleted($file, $user) {
$this->userDeletesFile($user, $file);
}

/**
* Wait for 1 second then delete a file/folder to avoid creating trashbin
* entries with the same timestamp. Only use this step to avoid the problem
* in core issue 23151 when wanting to demonstrate other correct behavior
*
* @When /^user "([^"]*)" waits and deletes (?:file|folder) "([^"]*)" using the WebDAV API$/
* @Given /^user "([^"]*)" has waited and deleted (?:file|folder) "([^"]*)"$/
*
* @param string $user
* @param string $file
*
* @return void
*/
public function userWaitsAndDeletesFile($user, $file) {
// prevent creating two files in the trashbin with the same timestamp
// which is based on seconds. e.g. deleting a/file.txt and b/file.txt
// might result in a name clash file.txt.d1456657282 in the trashbin
\sleep(1);
$this->userDeletesFile($user, $file);
}

/**
* @When /^user "([^"]*)" (?:deletes|unshares) (?:file|folder) "([^"]*)" using the WebDAV API$/
* @Given /^user "([^"]*)" has (?:deleted|unshared) (?:file|folder) "([^"]*)"$/
Expand All @@ -1901,7 +1880,9 @@ public function userWaitsAndDeletesFile($user, $file) {
* @return void
*/
public function userDeletesFile($user, $file) {
$this->pauseUploadDelete();
$this->response = $this->makeDavRequest($user, 'DELETE', $file, []);
$this->lastUploadDeleteTime = \time();
}

/**
Expand All @@ -1913,7 +1894,7 @@ public function userDeletesFile($user, $file) {
* @return void
*/
public function theUserDeletesFile($file) {
$this->response = $this->makeDavRequest($this->getCurrentUser(), 'DELETE', $file, []);
$this->userDeletesFile($this->getCurrentUser(), $file);
}

/**
Expand Down Expand Up @@ -2035,11 +2016,11 @@ public function userUploadsChunkedFile(
$num -= 1;
$data = \GuzzleHttp\Stream\Stream::factory($data);
$file = "$destination-chunking-42-$total-$num";
$this->pauseUpload();
$this->pauseUploadDelete();
$this->response = $this->makeDavRequest(
$user, 'PUT', $file, ['OC-Chunked' => '1'], $data, "uploads"
);
$this->lastUploadTime = \time();
$this->lastUploadDeleteTime = \time();
}

/**
Expand Down Expand Up @@ -2089,7 +2070,7 @@ public function userUploadsTheFollowingChunksUsingNewChunking(
public function userUploadsChunksUsingNewChunking(
$user, $file, $chunkingId, $chunkDetails, $async = false
) {
$this->pauseUpload();
$this->pauseUploadDelete();
$this->userCreatesANewChunkingUploadWithId($user, $chunkingId);
foreach ($chunkDetails as $chunkDetail) {
$chunkNumber = $chunkDetail[0];
Expand All @@ -2101,7 +2082,7 @@ public function userUploadsChunksUsingNewChunking(
$headers = ['OC-LazyOps' => 'true'];
}
$this->moveNewDavChunkToFinalFile($user, $chunkingId, $file, $headers);
$this->lastUploadTime = \time();
$this->lastUploadDeleteTime = \time();
}

/**
Expand Down Expand Up @@ -2625,9 +2606,9 @@ public function findEntryFromPropfindResponse($user, $entryNameToSearch = null)
*
* @return void
*/
public function pauseUpload() {
public function pauseUploadDelete() {
$time = \time();
if ($this->lastUploadTime !== null && $time - $this->lastUploadTime < 1) {
if ($this->lastUploadDeleteTime !== null && $time - $this->lastUploadDeleteTime < 1) {
\sleep(1);
}
}
Expand Down

0 comments on commit 58f2eeb

Please sign in to comment.