From 9b1ad5763cea9f418dd4c79671fa98cbd3e3fbee Mon Sep 17 00:00:00 2001 From: Phil Davis <phil@jankaritech.com> Date: Tue, 18 Jul 2023 14:15:46 +0545 Subject: [PATCH] Retry if 409 is received when uploading in a Given step --- tests/TestHelpers/UploadHelper.php | 45 +++- .../acceptance/features/bootstrap/WebDav.php | 243 ++++++++++++++---- 2 files changed, 236 insertions(+), 52 deletions(-) diff --git a/tests/TestHelpers/UploadHelper.php b/tests/TestHelpers/UploadHelper.php index d5be3e19ffe..856673e1dd5 100644 --- a/tests/TestHelpers/UploadHelper.php +++ b/tests/TestHelpers/UploadHelper.php @@ -49,6 +49,7 @@ class UploadHelper extends Assert { * @param int|null $chunkingVersion (1|2|null) * if set to null chunking will not be used * @param int|null $noOfChunks how many chunks to upload + * @param bool|null $isGivenStep * * @return ResponseInterface * @throws GuzzleException @@ -63,7 +64,8 @@ public static function upload( ?array $headers = [], ?int $davPathVersionToUse = 1, ?int $chunkingVersion = null, - ?int $noOfChunks = 1 + ?int $noOfChunks = 1, + ?bool $isGivenStep = false ): ResponseInterface { //simple upload with no chunking if ($chunkingVersion === null) { @@ -77,7 +79,16 @@ public static function upload( $headers, $xRequestId, $data, - $davPathVersionToUse + $davPathVersionToUse, + "files", + null, + "basic", + false, + 0, + null, + [], + null, + $isGivenStep ); } else { //prepare chunking @@ -102,7 +113,15 @@ public static function upload( $xRequestId, null, $davPathVersionToUse, - "uploads" + "uploads", + null, + "basic", + false, + 0, + null, + [], + null, + $isGivenStep ); if ($result->getStatusCode() >= 400) { return $result; @@ -130,7 +149,15 @@ public static function upload( $xRequestId, $chunk, $davPathVersionToUse, - $davRequestType + $davRequestType, + null, + "basic", + false, + 0, + null, + [], + null, + $isGivenStep ); if ($result->getStatusCode() >= 400) { return $result; @@ -152,7 +179,15 @@ public static function upload( $xRequestId, null, $davPathVersionToUse, - "uploads" + "uploads", + null, + "basic", + false, + 0, + null, + [], + null, + $isGivenStep ); if ($result->getStatusCode() >= 400) { return $result; diff --git a/tests/acceptance/features/bootstrap/WebDav.php b/tests/acceptance/features/bootstrap/WebDav.php index 50c669fa426..5088a8ef5f5 100644 --- a/tests/acceptance/features/bootstrap/WebDav.php +++ b/tests/acceptance/features/bootstrap/WebDav.php @@ -2047,10 +2047,16 @@ public function checkElementList( * @param string $user * @param string $source * @param string $destination + * @param bool|null $isGivenStep * * @return void */ - public function userUploadsAFileTo(string $user, string $source, string $destination):void { + public function userUploadsAFileTo( + string $user, + string $source, + string $destination, + ?bool $isGivenStep = false + ):void { $user = $this->getActualUsername($user); $file = \fopen($this->acceptanceTestsDirLocation() . $source, 'r'); $this->pauseUploadDelete(); @@ -2059,7 +2065,14 @@ public function userUploadsAFileTo(string $user, string $source, string $destina "PUT", $destination, [], - $file + $file, + "files", + null, + false, + null, + [], + null, + $isGivenStep ); $this->lastUploadDeleteTime = \time(); $this->setResponseXml( @@ -2080,7 +2093,7 @@ public function userUploadsAFileTo(string $user, string $source, string $destina * @return void */ public function userHasUploadedAFileTo(string $user, string $source, string $destination):void { - $this->userUploadsAFileTo($user, $source, $destination); + $this->userUploadsAFileTo($user, $source, $destination, true); $this->theHTTPStatusCodeShouldBe( ["201", "204"], "HTTP status code was not 201 or 204 while trying to upload file '$source' to '$destination' for user '$user'" @@ -2093,11 +2106,16 @@ public function userHasUploadedAFileTo(string $user, string $source, string $des * * @param string $source * @param string $destination + * @param bool|null $isGivenStep * * @return void */ - public function theUserUploadsAFileTo(string $source, string $destination):void { - $this->userUploadsAFileTo($this->currentUser, $source, $destination); + public function theUserUploadsAFileTo( + string $source, + string $destination, + ?bool $isGivenStep = false + ):void { + $this->userUploadsAFileTo($this->currentUser, $source, $destination, $isGivenStep); } /** @@ -2109,7 +2127,7 @@ public function theUserUploadsAFileTo(string $source, string $destination):void * @return void */ public function theUserHasUploadedFileTo(string $source, string $destination):void { - $this->theUserUploadsAFileTo($source, $destination); + $this->theUserUploadsAFileTo($source, $destination, true); $this->theHTTPStatusCodeShouldBe( ["201", "204"], "HTTP status code was not 201 or 204 while trying to upload file '$source' to '$destination'" @@ -2123,12 +2141,19 @@ public function theUserHasUploadedFileTo(string $source, string $destination):vo * @param string $server * @param string $source * @param string $destination + * @param bool|null $isGivenStep * * @return void */ - public function userOnUploadsAFileTo(string $user, string $server, string $source, string $destination):void { + public function userOnUploadsAFileTo( + string $user, + string $server, + string $source, + string $destination, + ?bool $isGivenStep = false + ):void { $previousServer = $this->usingServer($server); - $this->userUploadsAFileTo($user, $source, $destination); + $this->userUploadsAFileTo($user, $source, $destination, $isGivenStep); $this->usingServer($previousServer); } @@ -2143,7 +2168,7 @@ public function userOnUploadsAFileTo(string $user, string $server, string $sourc * @return void */ public function userOnHasUploadedAFileTo(string $user, string $server, string $source, string $destination):void { - $this->userOnUploadsAFileTo($user, $server, $source, $destination); + $this->userOnUploadsAFileTo($user, $server, $source, $destination, true); $this->theHTTPStatusCodeShouldBe( ["201", "204"], "HTTP status code was not 201 or 204 while trying to upload file '$source' to '$destination' for user '$user' on server '$server'" @@ -2807,7 +2832,7 @@ public function asUserOnServerTheFilesUploadedToWithAllMechanismsShouldExit( */ public function userHasUploadedFileToOfSizeBytes(string $user, string $destination, string $bytes):void { $user = $this->getActualUsername($user); - $this->userUploadsAFileToOfSizeBytes($user, $destination, $bytes); + $this->userUploadsAFileToOfSizeBytes($user, $destination, $bytes, true); $expectedElements = new TableNode([["$destination"]]); $this->checkElementList($user, $expectedElements); } @@ -2818,11 +2843,23 @@ public function userHasUploadedFileToOfSizeBytes(string $user, string $destinati * @param string $user * @param string $destination * @param string $bytes + * @param bool|null $isGivenStep * * @return void */ - public function userUploadsAFileToOfSizeBytes(string $user, string $destination, string $bytes):void { - $this->userUploadsAFileToEndingWithOfSizeBytes($user, $destination, 'a', $bytes); + public function userUploadsAFileToOfSizeBytes( + string $user, + string $destination, + string $bytes, + ?bool $isGivenStep = false + ):void { + $this->userUploadsAFileToEndingWithOfSizeBytes( + $user, + $destination, + 'a', + $bytes, + $isGivenStep + ); } /** @@ -2837,7 +2874,7 @@ public function userUploadsAFileToOfSizeBytes(string $user, string $destination, * @throws Exception */ public function userHasUploadedFileToEndingWithOfSizeBytes(string $user, string $destination, string $text, string $bytes):void { - $this->userUploadsAFileToEndingWithOfSizeBytes($user, $destination, $text, $bytes); + $this->userUploadsAFileToEndingWithOfSizeBytes($user, $destination, $text, $bytes, true); $expectedElements = new TableNode([["$destination"]]); $this->checkElementList($user, $expectedElements); } @@ -2849,17 +2886,25 @@ public function userHasUploadedFileToEndingWithOfSizeBytes(string $user, string * @param string $destination * @param string $text * @param string $bytes + * @param bool|null $isGivenStep * * @return void */ - public function userUploadsAFileToEndingWithOfSizeBytes(string $user, string $destination, string $text, string $bytes):void { + public function userUploadsAFileToEndingWithOfSizeBytes( + string $user, + string $destination, + string $text, + string $bytes, + ?bool $isGivenStep = false + ):void { $filename = "filespecificSize.txt"; $this->createLocalFileOfSpecificSize($filename, $bytes, $text); Assert::assertFileExists($this->workStorageDirLocation() . $filename); $this->userUploadsAFileTo( $user, $this->temporaryStorageSubfolderName() . "/$filename", - $destination + $destination, + $isGivenStep ); $this->removeFile($this->workStorageDirLocation(), $filename); } @@ -2903,6 +2948,7 @@ public function userUploadsFilesWithContentTo( * @param string $user * @param string|null $content * @param string $destination + * @param bool|null $isGivenStep * * @return string[] * @throws JsonException @@ -2911,7 +2957,8 @@ public function userUploadsFilesWithContentTo( public function uploadFileWithContent( string $user, ?string $content, - string $destination + string $destination, + ?bool $isGivenStep = false ): array { $user = $this->getActualUsername($user); $this->pauseUploadDelete(); @@ -2920,7 +2967,14 @@ public function uploadFileWithContent( "PUT", $destination, [], - $content + $content, + "files", + null, + false, + null, + [], + null, + $isGivenStep ); $this->setResponseXml( HttpRequestHelper::parseResponseAsXml($this->response) @@ -2956,7 +3010,7 @@ public function adminHasUploadedAFileWithContentTo( ?string $content, string $destination ):array { - $fileId = $this->uploadFileWithContent($this->getAdminUsername(), $content, $destination); + $fileId = $this->uploadFileWithContent($this->getAdminUsername(), $content, $destination, true); $this->theHTTPStatusCodeShouldBe( ["201", "204"], "HTTP status code was not 201 or 204 while trying to upload file '$destination'" @@ -3010,12 +3064,12 @@ public function userUploadsFollowingFilesWithContentTo( /** * @When user :user uploads file :source to :destination with mtime :mtime using the WebDAV API - * @Given user :user has uploaded file :source to :destination with mtime :mtime using the WebDAV API * * @param string $user * @param string $source * @param string $destination * @param string $mtime Time in human-readable format is taken as input which is converted into milliseconds that is used by API + * @param bool|null $isGivenStep * * @return void * @throws Exception @@ -3024,7 +3078,8 @@ public function userUploadsFileToWithMtimeUsingTheWebdavApi( string $user, string $source, string $destination, - string $mtime + string $mtime, + ?bool $isGivenStep = false ):void { $mtime = new DateTime($mtime); $mtime = $mtime->format('U'); @@ -3037,7 +3092,36 @@ public function userUploadsFileToWithMtimeUsingTheWebdavApi( $destination, $this->getStepLineRef(), ["X-OC-Mtime" => $mtime], - $this->getDavPathVersion() + $this->getDavPathVersion(), + null, + 1, + $isGivenStep + ); + } + + /** + * @Given user :user has uploaded file :source to :destination with mtime :mtime using the WebDAV API + * + * @param string $user + * @param string $source + * @param string $destination + * @param string $mtime Time in human-readable format is taken as input which is converted into milliseconds that is used by API + * + * @return void + * @throws Exception + */ + public function userHasUploadedFileToWithMtimeUsingTheWebdavApi( + string $user, + string $source, + string $destination, + string $mtime + ):void { + $this->userUploadsFileToWithMtimeUsingTheWebdavApi( + $user, + $source, + $destination, + $mtime, + true ); } @@ -3072,7 +3156,17 @@ public function userUploadsFileWithContentAndWithMtimeOfDaysAgoUsingWebdavApi( $filename, ["X-OC-Mtime" => $mtime], $this->getStepLineRef(), - $content + $content, + WebDavHelper::DAV_VERSION_OLD, + "files", + null, + "basic", + false, + 0, + null, + [], + null, + true ); } @@ -3157,7 +3251,7 @@ public function userHasUploadedAFileWithContentTo( string $destination ):array { $user = $this->getActualUsername($user); - $fileId = $this->uploadFileWithContent($user, $content, $destination); + $fileId = $this->uploadFileWithContent($user, $content, $destination, true); $this->theHTTPStatusCodeShouldBe( ["201", "204"], "HTTP status code was not 201 or 204 while trying to upload file '$destination' for user '$user'" @@ -3254,6 +3348,7 @@ public function userUploadsAFileWithContentAndMtimeTo( * @param string $checksum * @param string|null $content * @param string $destination + * @param bool|null $isGivenStep * * @return void */ @@ -3261,7 +3356,8 @@ public function userUploadsAFileWithChecksumAndContentTo( string $user, string $checksum, ?string $content, - string $destination + string $destination, + ?bool $isGivenStep = false ):void { $this->pauseUploadDelete(); $this->response = $this->makeDavRequest( @@ -3269,7 +3365,14 @@ public function userUploadsAFileWithChecksumAndContentTo( "PUT", $destination, ['OC-Checksum' => $checksum], - $content + $content, + "files", + null, + false, + null, + [], + null, + $isGivenStep ); $this->lastUploadDeleteTime = \time(); $this->pushToLastStatusCodesArrays(); @@ -3295,7 +3398,8 @@ public function userHasUploadedAFileWithChecksumAndContentTo( $user, $checksum, $content, - $destination + $destination, + true ); $this->theHTTPStatusCodeShouldBe( ["201", "204"], @@ -3590,7 +3694,7 @@ public function adminHasCreatedFolder(string $destination):void { $admin, __METHOD__ . "The provided user is not admin but '" . $admin . "'" ); - $this->userCreatesFolder($admin, $destination); + $this->userCreatesFolder($admin, $destination, true); $this->theHTTPStatusCodeShouldBe( ["201", "204"], "HTTP status code was not 201 or 204 while trying to create folder '$destination' for admin '$admin'" @@ -3754,6 +3858,7 @@ public function userUploadsTheFollowingChunksUsingOldChunking( * @param int $total * @param string|null $data * @param string $destination + * @param bool|null $isGivenStep * * @return void */ @@ -3762,7 +3867,8 @@ public function userUploadsChunkedFile( int $num, int $total, ?string $data, - string $destination + string $destination, + ?bool $isGivenStep = false ):void { $user = $this->getActualUsername($user); $num -= 1; @@ -3774,7 +3880,13 @@ public function userUploadsChunkedFile( $file, ['OC-Chunked' => '1'], $data, - "uploads" + "uploads", + null, + false, + null, + [], + null, + $isGivenStep ); $this->lastUploadDeleteTime = \time(); } @@ -3800,7 +3912,7 @@ public function userHasUploadedChunkedFile( string $destination ):void { $user = $this->getActualUsername($user); - $this->userUploadsChunkedFile($user, $num, $total, $data, $destination); + $this->userUploadsChunkedFile($user, $num, $total, $data, $destination, true); $this->theHTTPStatusCodeShouldBe( ["201", "204"], "HTTP status code was not 201 or 204 while trying to upload chunk $num of $total to file '$destination' for user '$user'" @@ -3882,7 +3994,7 @@ public function userHasUploadedTheFollowingChunksUsingNewChunking( * | 1 | first data | * | 2 | second data | * Chunks may be numbered out-of-order if desired. - * @param bool $checkActions + * @param bool|null $isGivenStep * * @return void * @throws Exception @@ -3892,7 +4004,7 @@ public function uploadTheFollowingChunksUsingNewChunking( string $type, string $file, TableNode $chunkDetails, - bool $checkActions = false + ?bool $isGivenStep = false ):void { $user = $this->getActualUsername($user); $async = false; @@ -3906,7 +4018,7 @@ public function uploadTheFollowingChunksUsingNewChunking( 'chunking-42', $chunkDetails->getHash(), $async, - $checkActions + $isGivenStep ); } @@ -3922,7 +4034,7 @@ public function uploadTheFollowingChunksUsingNewChunking( * [content] data content of the chunk * Chunks may be numbered out-of-order if desired. * @param bool $async use asynchronous MOVE at the end or not - * @param bool $checkActions + * @param bool $isGivenStep * * @return void */ @@ -3932,10 +4044,10 @@ public function userUploadsChunksUsingNewChunking( string $chunkingId, array $chunkDetails, bool $async = false, - bool $checkActions = false + bool $isGivenStep = false ):void { $this->pauseUploadDelete(); - if ($checkActions) { + if ($isGivenStep) { $this->userHasCreatedANewChunkingUploadWithId($user, $chunkingId); } else { $this->userCreatesANewChunkingUploadWithId($user, $chunkingId); @@ -3943,7 +4055,7 @@ public function userUploadsChunksUsingNewChunking( foreach ($chunkDetails as $chunkDetail) { $chunkNumber = (int)$chunkDetail['number']; $chunkContent = $chunkDetail['content']; - if ($checkActions) { + if ($isGivenStep) { $this->userHasUploadedNewChunkFileOfWithToId($user, $chunkNumber, $chunkContent, $chunkingId); } else { $this->userUploadsNewChunkFileOfWithToId($user, $chunkNumber, $chunkContent, $chunkingId); @@ -3953,8 +4065,8 @@ public function userUploadsChunksUsingNewChunking( if ($async === true) { $headers = ['OC-LazyOps' => 'true']; } - $this->moveNewDavChunkToFinalFile($user, $chunkingId, $file, $headers); - if ($checkActions) { + $this->moveNewDavChunkToFinalFile($user, $chunkingId, $file, $headers, $isGivenStep); + if ($isGivenStep) { $this->theHTTPStatusCodeShouldBeSuccess(); } $this->lastUploadDeleteTime = \time(); @@ -3965,10 +4077,15 @@ public function userUploadsChunksUsingNewChunking( * * @param string $user * @param string $id + * @param bool|null $isGivenStep * * @return void */ - public function userCreatesANewChunkingUploadWithId(string $user, string $id):void { + public function userCreatesANewChunkingUploadWithId( + string $user, + string $id, + ?bool $isGivenStep = false + ):void { $user = $this->getActualUsername($user); $destination = "/uploads/$user/$id"; $this->response = $this->makeDavRequest( @@ -3977,7 +4094,13 @@ public function userCreatesANewChunkingUploadWithId(string $user, string $id):vo $destination, [], null, - "uploads" + "uploads", + null, + false, + null, + [], + null, + $isGivenStep ); } @@ -3990,7 +4113,7 @@ public function userCreatesANewChunkingUploadWithId(string $user, string $id):vo * @return void */ public function userHasCreatedANewChunkingUploadWithId(string $user, string $id):void { - $this->userCreatesANewChunkingUploadWithId($user, $id); + $this->userCreatesANewChunkingUploadWithId($user, $id, true); $this->theHTTPStatusCodeShouldBeSuccess(); } @@ -4001,10 +4124,17 @@ public function userHasCreatedANewChunkingUploadWithId(string $user, string $id) * @param int $num * @param string|null $data * @param string $id + * @param bool|null $isGivenStep * * @return void */ - public function userUploadsNewChunkFileOfWithToId(string $user, int $num, ?string $data, string $id):void { + public function userUploadsNewChunkFileOfWithToId( + string $user, + int $num, + ?string $data, + string $id, + ?bool $isGivenStep = false + ):void { $user = $this->getActualUsername($user); $destination = "/uploads/$user/$id/$num"; $this->response = $this->makeDavRequest( @@ -4013,7 +4143,13 @@ public function userUploadsNewChunkFileOfWithToId(string $user, int $num, ?strin $destination, [], $data, - "uploads" + "uploads", + null, + false, + null, + [], + null, + $isGivenStep ); $this->pushToLastStatusCodesArrays(); } @@ -4029,7 +4165,7 @@ public function userUploadsNewChunkFileOfWithToId(string $user, int $num, ?strin * @return void */ public function userHasUploadedNewChunkFileOfWithToId(string $user, int $num, ?string $data, string $id):void { - $this->userUploadsNewChunkFileOfWithToId($user, $num, $data, $id); + $this->userUploadsNewChunkFileOfWithToId($user, $num, $data, $id, true); $this->theHTTPStatusCodeShouldBeSuccess(); } @@ -4232,10 +4368,17 @@ public function userHasMovedNewChunkFileWithIdToMychunkedfileWithChecksum( * @param string $id upload id * @param string $destination destination path * @param array $headers extra headers + * @param bool|null $isGivenStep * * @return void */ - private function moveNewDavChunkToFinalFile(string $user, string $id, string $destination, array $headers):void { + private function moveNewDavChunkToFinalFile( + string $user, + string $id, + string $destination, + array $headers, + ?bool $isGivenStep = false + ):void { $user = $this->getActualUsername($user); $source = "/uploads/$user/$id/.file"; $headers['Destination'] = $this->destinationHeaderValue( @@ -4249,7 +4392,13 @@ private function moveNewDavChunkToFinalFile(string $user, string $id, string $de $source, $headers, null, - "uploads" + "uploads", + null, + false, + null, + [], + null, + $isGivenStep ); }