Skip to content

Commit 949f14a

Browse files
committed
test: add test to check mismatch offset during TUS upload
Signed-off-by: Saw-jan <saw.jan.grg3e@gmail.com>
1 parent 27450c9 commit 949f14a

2 files changed

Lines changed: 55 additions & 2 deletions

File tree

tests/acceptance/bootstrap/TUSContext.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,44 @@ public function uploadChunkToTUSLocation(
216216
);
217217
}
218218

219+
/**
220+
* @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
221+
*
222+
* @param string $user
223+
* @param string $offset
224+
* @param string $data
225+
*
226+
* @return void
227+
*
228+
* @throws GuzzleException
229+
* @throws JsonException
230+
*/
231+
public function userSendsAChunkToTUSLocationWithOffsetAndDataWithRetryOnOffsetMismatch(
232+
string $user,
233+
string $offset,
234+
string $data,
235+
): void {
236+
$resourceLocation = $this->getLastTusResourceLocation();
237+
238+
$retried = 0;
239+
do {
240+
$tryAgain = false;
241+
$response = $this->uploadChunkToTUSLocation($user, $resourceLocation, $offset, $data);
242+
// retry on 409 Conflict (Offset mismatch during TUS upload)
243+
if ($response->getStatusCode() === 409) {
244+
$tryAgain = true;
245+
}
246+
$tryAgain = $tryAgain && $retried < HttpRequestHelper::numRetriesOnHttpTooEarly();
247+
if ($tryAgain) {
248+
$retried += 1;
249+
echo "Offset mismatch during TUS upload, retrying ($retried)...\n";
250+
// wait 1s and try again
251+
\sleep(1);
252+
}
253+
} while ($tryAgain);
254+
$this->featureContext->setResponse($response);
255+
}
256+
219257
/**
220258
* @When user :user sends a chunk to the last created TUS Location with offset :offset and data :data using the WebDAV API
221259
*

tests/acceptance/features/coreApiWebdavUploadTUS/lowLevelUpload.feature

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ Feature: low level tests for upload of chunks
5050
| Upload-Metadata | filename ZmlsZS50eHQ= |
5151
When user "Alice" sends a chunk to the last created TUS Location with offset "0" and data "123" using the WebDAV API
5252
And user "Alice" sends a chunk to the last created TUS Location with offset "3" and data "4567890" using the WebDAV API
53-
And the user waits for "2" seconds for postprocessing to finish
54-
And user "Alice" sends a chunk to the last created TUS Location with offset "3" and data "0000000" using the WebDAV API
53+
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
5554
Then the HTTP status code should be "404"
5655
And the content of file "/file.txt" for user "Alice" should be "1234567890"
5756
Examples:
@@ -61,6 +60,22 @@ Feature: low level tests for upload of chunks
6160
| spaces |
6261

6362

63+
Scenario Outline: send last chunk with mismatch offset
64+
Given using <dav-path-version> DAV path
65+
And user "Alice" has created a new TUS resource on the WebDAV API with these headers:
66+
| Upload-Length | 10 |
67+
# ZmlsZS50eHQ= is the base64 encode of file.txt
68+
| Upload-Metadata | filename ZmlsZS50eHQ= |
69+
When user "Alice" sends a chunk to the last created TUS Location with offset "0" and data "123" using the WebDAV API
70+
And user "Alice" sends a chunk to the last created TUS Location with offset "2" and data "34567890" using the WebDAV API
71+
Then the HTTP status code should be "409"
72+
Examples:
73+
| dav-path-version |
74+
| old |
75+
| new |
76+
| spaces |
77+
78+
6479
Scenario Outline: start with uploading not at the beginning of the file
6580
Given using <dav-path-version> DAV path
6681
And user "Alice" has created a new TUS resource on the WebDAV API with these headers:

0 commit comments

Comments
 (0)