diff --git a/tests/acceptance/bootstrap/TUSContext.php b/tests/acceptance/bootstrap/TUSContext.php index d8397db1a..425555c6e 100644 --- a/tests/acceptance/bootstrap/TUSContext.php +++ b/tests/acceptance/bootstrap/TUSContext.php @@ -216,6 +216,44 @@ class TUSContext implements Context { ); } + /** + * @When user :user sends a chunk to the last created TUS Location with offset :offset and data :data with retry on offset mismatch using the WebDAV API + * + * @param string $user + * @param string $offset + * @param string $data + * + * @return void + * + * @throws GuzzleException + * @throws JsonException + */ + public function userSendsAChunkToTUSLocationWithOffsetAndDataWithRetryOnOffsetMismatch( + string $user, + string $offset, + string $data, + ): void { + $resourceLocation = $this->getLastTusResourceLocation(); + + $retried = 0; + do { + $tryAgain = false; + $response = $this->uploadChunkToTUSLocation($user, $resourceLocation, $offset, $data); + // retry on 409 Conflict (Offset mismatch during TUS upload) + if ($response->getStatusCode() === 409) { + $tryAgain = true; + } + $tryAgain = $tryAgain && $retried < HttpRequestHelper::numRetriesOnHttpTooEarly(); + if ($tryAgain) { + $retried += 1; + echo "Offset mismatch during TUS upload, retrying ($retried)...\n"; + // wait 1s and try again + \sleep(1); + } + } while ($tryAgain); + $this->featureContext->setResponse($response); + } + /** * @When user :user sends a chunk to the last created TUS Location with offset :offset and data :data using the WebDAV API * diff --git a/tests/acceptance/features/coreApiWebdavUploadTUS/lowLevelUpload.feature b/tests/acceptance/features/coreApiWebdavUploadTUS/lowLevelUpload.feature index 3e5780e54..c34202b8d 100644 --- a/tests/acceptance/features/coreApiWebdavUploadTUS/lowLevelUpload.feature +++ b/tests/acceptance/features/coreApiWebdavUploadTUS/lowLevelUpload.feature @@ -50,8 +50,7 @@ Feature: low level tests for upload of chunks | Upload-Metadata | filename ZmlsZS50eHQ= | When user "Alice" sends a chunk to the last created TUS Location with offset "0" and data "123" using the WebDAV API And user "Alice" sends a chunk to the last created TUS Location with offset "3" and data "4567890" using the WebDAV API - And the user waits for "2" seconds for postprocessing to finish - And user "Alice" sends a chunk to the last created TUS Location with offset "3" and data "0000000" using the WebDAV API + And user "Alice" sends a chunk to the last created TUS Location with offset "3" and data "0000000" with retry on offset mismatch using the WebDAV API Then the HTTP status code should be "404" And the content of file "/file.txt" for user "Alice" should be "1234567890" Examples: @@ -61,6 +60,22 @@ Feature: low level tests for upload of chunks | spaces | + Scenario Outline: send last chunk with mismatch offset + Given using DAV path + And user "Alice" has created a new TUS resource on the WebDAV API with these headers: + | Upload-Length | 10 | + # ZmlsZS50eHQ= is the base64 encode of file.txt + | Upload-Metadata | filename ZmlsZS50eHQ= | + When user "Alice" sends a chunk to the last created TUS Location with offset "0" and data "123" using the WebDAV API + And user "Alice" sends a chunk to the last created TUS Location with offset "2" and data "34567890" using the WebDAV API + Then the HTTP status code should be "409" + Examples: + | dav-path-version | + | old | + | new | + | spaces | + + Scenario Outline: start with uploading not at the beginning of the file Given using DAV path And user "Alice" has created a new TUS resource on the WebDAV API with these headers: