From e84cbfd90b1541f7f9bbd09eb2a2fba1842ac034 Mon Sep 17 00:00:00 2001 From: Artur Neumann Date: Fri, 7 Dec 2018 09:05:18 +0545 Subject: [PATCH] pause upload to prevent files with same etag --- .../acceptance/features/bootstrap/WebDav.php | 30 +++++++++++++++---- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/tests/acceptance/features/bootstrap/WebDav.php b/tests/acceptance/features/bootstrap/WebDav.php index c03645ad7b05..057ed01215a8 100644 --- a/tests/acceptance/features/bootstrap/WebDav.php +++ b/tests/acceptance/features/bootstrap/WebDav.php @@ -1674,9 +1674,11 @@ public function userUploadsAFileTo($user, $source, $destination) { 'r' ) ); + $this->pauseUpload(); $this->response = $this->makeDavRequest( $user, "PUT", $destination, [], $file ); + $this->lastUploadTime = \time(); $this->parseResponseIntoXml(); } @@ -1751,6 +1753,7 @@ public function userUploadsAFileToWithChunks( } try { $this->responseXml = []; + $this->pauseUpload(); $this->response = UploadHelper::upload( $this->getBaseUrl(), $this->getActualUsername($user), @@ -1762,6 +1765,7 @@ public function userUploadsAFileToWithChunks( $this->chunkingToUse, $noOfChunks ); + $this->lastUploadTime = \time(); } catch (BadResponseException $e) { // 4xx and 5xx responses cause an exception $this->response = $e->getResponse(); @@ -2082,12 +2086,7 @@ public function userUploadsAFileWithContentTo( $user, $content, $destination ) { $file = \GuzzleHttp\Stream\Stream::factory($content); - $time = \time(); - if ($this->lastUploadTime !== null && $time - $this->lastUploadTime < 1) { - // prevent creating two uploads with the same "stime" which is - // based on seconds, this prevents creation of uploads with same etag - \sleep(1); - } + $this->pauseUpload(); $this->response = $this->makeDavRequest( $user, "PUT", $destination, [], $file ); @@ -2110,6 +2109,7 @@ public function userUploadsAFileWithChecksumAndContentTo( $user, $checksum, $content, $destination ) { $file = \GuzzleHttp\Stream\Stream::factory($content); + $this->pauseUpload(); $this->response = $this->makeDavRequest( $user, "PUT", @@ -2117,6 +2117,7 @@ public function userUploadsAFileWithChecksumAndContentTo( ['OC-Checksum' => $checksum], $file ); + $this->lastUploadTime = \time(); } /** @@ -2294,9 +2295,11 @@ public function userUploadsChunkedFile( $num -= 1; $data = \GuzzleHttp\Stream\Stream::factory($data); $file = "$destination-chunking-42-$total-$num"; + $this->pauseUpload(); $this->response = $this->makeDavRequest( $user, 'PUT', $file, ['OC-Chunked' => '1'], $data, "uploads" ); + $this->lastUploadTime = \time(); } /** @@ -2346,6 +2349,7 @@ public function userUploadsTheFollowingChunksUsingNewChunking( public function userUploadsChunksUsingNewChunking( $user, $file, $chunkingId, $chunkDetails, $async = false ) { + $this->pauseUpload(); $this->userCreatesANewChunkingUploadWithId($user, $chunkingId); foreach ($chunkDetails as $chunkDetail) { $chunkNumber = $chunkDetail[0]; @@ -2357,6 +2361,7 @@ public function userUploadsChunksUsingNewChunking( $headers = ['OC-LazyOps' => 'true']; } $this->moveNewDavChunkToFinalFile($user, $chunkingId, $file, $headers); + $this->lastUploadTime = \time(); } /** @@ -3097,6 +3102,19 @@ public function findEntryFromPropfindResponse($user, $entryNameToSearch = null) return false; } + /** + * prevent creating two uploads with the same "stime" which is + * based on seconds, this prevents creation of uploads with same etag + * + * @return void + */ + public function pauseUpload() { + $time = \time(); + if ($this->lastUploadTime !== null && $time - $this->lastUploadTime < 1) { + \sleep(1); + } + } + /** * reset settings if they were set in the scenario *