Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit 4867c1e

Browse files
authored
resumeMultipartUpload of R2Bucket should not be async (#505)
* resumeMultipartUpload of R2Bucket should not be async * Tests are fixed
1 parent 6a0b370 commit 4867c1e

File tree

2 files changed

+17
-23
lines changed

2 files changed

+17
-23
lines changed

packages/r2/src/bucket.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -816,10 +816,7 @@ export class R2Bucket {
816816
return upload;
817817
}
818818

819-
async resumeMultipartUpload(
820-
key: string,
821-
uploadId: string
822-
): Promise<R2MultipartUpload> {
819+
resumeMultipartUpload(key: string, uploadId: string): R2MultipartUpload {
823820
// The Workers runtime doesn't make a subrequest here, so no need to call
824821
// `prepareCtx()`
825822

packages/r2/test/multipart.spec.ts

+16-19
Original file line numberDiff line numberDiff line change
@@ -116,33 +116,33 @@ test("R2Bucket: resumeMultipartUpload", async (t) => {
116116
const { r2 } = t.context;
117117

118118
// Check creates upload object with correct key and uploadId
119-
let upload = await r2.resumeMultipartUpload("key", "upload");
119+
let upload = r2.resumeMultipartUpload("key", "upload");
120120
t.is(upload.key, "key");
121121
t.is(upload.uploadId, "upload");
122122

123123
// Check validates key and uploadId provided, but not key length
124124
// @ts-expect-error intentionally testing incorrect types
125-
await t.throwsAsync(r2.resumeMultipartUpload(), {
125+
t.throws(() => r2.resumeMultipartUpload(), {
126126
instanceOf: TypeError,
127127
message:
128128
"Failed to execute 'resumeMultipartUpload' on 'R2Bucket': parameter 1 is not of type 'string'.",
129129
});
130130
// @ts-expect-error intentionally testing incorrect types
131-
await t.throwsAsync(r2.resumeMultipartUpload("key"), {
131+
t.throws(() => r2.resumeMultipartUpload("key"), {
132132
instanceOf: TypeError,
133133
message:
134134
"Failed to execute 'resumeMultipartUpload' on 'R2Bucket': parameter 2 is not of type 'string'.",
135135
});
136-
upload = await r2.resumeMultipartUpload("x".repeat(1025), "upload");
136+
upload = r2.resumeMultipartUpload("x".repeat(1025), "upload");
137137
t.is(upload.key, "x".repeat(1025));
138138

139139
// Check coerces key and uploadId to string
140140
// @ts-expect-error intentionally testing incorrect types
141-
upload = await r2.resumeMultipartUpload(1, 2);
141+
upload = r2.resumeMultipartUpload(1, 2);
142142
t.is(upload.key, "1");
143143
t.is(upload.uploadId, "2");
144144
// @ts-expect-error intentionally testing incorrect types
145-
upload = await r2.resumeMultipartUpload(undefined, undefined);
145+
upload = r2.resumeMultipartUpload(undefined, undefined);
146146
t.is(upload.key, "undefined");
147147
t.is(upload.uploadId, "undefined");
148148
});
@@ -220,12 +220,12 @@ test("R2MultipartUpload: uploadPart", async (t) => {
220220

221221
// Check validates key and uploadId
222222
let expectations = doesNotExistExpectations("uploadPart");
223-
let nonExistentUpload = await r2.resumeMultipartUpload("key", "bad");
223+
let nonExistentUpload = r2.resumeMultipartUpload("key", "bad");
224224
await t.throwsAsync(nonExistentUpload.uploadPart(1, "value"), expectations);
225-
nonExistentUpload = await r2.resumeMultipartUpload("badkey", upload.uploadId);
225+
nonExistentUpload = r2.resumeMultipartUpload("badkey", upload.uploadId);
226226
await t.throwsAsync(nonExistentUpload.uploadPart(1, "value"), expectations);
227227
expectations = objectNameNotValidExpectations("uploadPart");
228-
nonExistentUpload = await r2.resumeMultipartUpload("x".repeat(1025), "bad");
228+
nonExistentUpload = r2.resumeMultipartUpload("x".repeat(1025), "bad");
229229
await t.throwsAsync(nonExistentUpload.uploadPart(1, "value"), expectations);
230230

231231
// Check validates part number (before key and uploadId)
@@ -331,12 +331,12 @@ test("R2MultipartUpload: abort", async (t) => {
331331
const upload3 = await r2.createMultipartUpload("key");
332332
// Note this is internalErrorExpectations, not doesNotExistExpectations
333333
expectations = internalErrorExpectations("abortMultipartUpload");
334-
let nonExistentUpload = await r2.resumeMultipartUpload("key", "bad");
334+
let nonExistentUpload = r2.resumeMultipartUpload("key", "bad");
335335
await t.throwsAsync(nonExistentUpload.abort(), expectations);
336-
nonExistentUpload = await r2.resumeMultipartUpload("bad", upload3.uploadId);
336+
nonExistentUpload = r2.resumeMultipartUpload("bad", upload3.uploadId);
337337
await t.throwsAsync(nonExistentUpload.abort(), expectations);
338338
expectations = objectNameNotValidExpectations("abortMultipartUpload");
339-
nonExistentUpload = await r2.resumeMultipartUpload("x".repeat(1025), "bad");
339+
nonExistentUpload = r2.resumeMultipartUpload("x".repeat(1025), "bad");
340340
await t.throwsAsync(nonExistentUpload.abort(), expectations);
341341
});
342342
test("R2MultipartUpload: complete", async (t) => {
@@ -511,15 +511,12 @@ test("R2MultipartUpload: complete", async (t) => {
511511
const upload11 = await r2.createMultipartUpload("key");
512512
// Note this is internalErrorExpectations, not doesNotExistExpectations
513513
let expectations = internalErrorExpectations("completeMultipartUpload");
514-
let nonExistentUpload = await r2.resumeMultipartUpload("key", "bad");
514+
let nonExistentUpload = r2.resumeMultipartUpload("key", "bad");
515515
await t.throwsAsync(nonExistentUpload.complete([]), expectations);
516-
nonExistentUpload = await r2.resumeMultipartUpload(
517-
"badkey",
518-
upload11.uploadId
519-
);
516+
nonExistentUpload = r2.resumeMultipartUpload("badkey", upload11.uploadId);
520517
await t.throwsAsync(nonExistentUpload.complete([]), expectations);
521518
expectations = objectNameNotValidExpectations("completeMultipartUpload");
522-
nonExistentUpload = await r2.resumeMultipartUpload("x".repeat(1025), "bad");
519+
nonExistentUpload = r2.resumeMultipartUpload("x".repeat(1025), "bad");
523520
await t.throwsAsync(nonExistentUpload.complete([]), expectations);
524521

525522
// Check validates uploaded parts
@@ -872,7 +869,7 @@ test("R2Bucket/R2MultipartUpload: operations throw outside request handler", asy
872869
await t.throwsAsync(r2.createMultipartUpload("key"), expectations);
873870
// (resumeMultipartUpload() doesn't make any "network" calls, so can be called
874871
// outside a request context)
875-
await r2.resumeMultipartUpload("key", "upload");
872+
r2.resumeMultipartUpload("key", "upload");
876873

877874
t.is(ctx.internalSubrequests, 0);
878875
const upload = await ctx.runWith(() => r2.createMultipartUpload("key"));

0 commit comments

Comments
 (0)