Skip to content

Commit dfbda26

Browse files
authored
Fix flaky tests and s3 kit warnings (#423)
* fix(e2e): send an explicit empty body for directory markers (#369) The AWS SDK sets no Content-Length for an empty string body and warns about a stream of unknown length on every directory marker. * fix(e2e): wait for the URL to be restored after a cancelled Back (#369) SvelteKit restores the URL of a cancelled popstate navigation with history.go, so the leave warning can be visible before the URL is back. This flaked on Firefox in CI. * fix(e2e): tolerate a concurrent bucket creation in Garage setup Two workers provisioning the same bucket could both miss it in the lookup and the second CreateBucket failed with 409. Look the bucket up again when the creation fails.
1 parent b3cf3b4 commit dfbda26

3 files changed

Lines changed: 17 additions & 3 deletions

File tree

‎e2e/storage/helpers.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,10 @@ export async function putTextObject(
206206
}
207207

208208
export async function putDirectoryMarker(client: S3Client, bucket: string, key: string) {
209-
await client.send(new PutObjectCommand({ Bucket: bucket, Key: key, Body: '' }));
209+
// The SDK sets no Content-Length for a falsy body, so '' triggers its stream warning.
210+
await client.send(
211+
new PutObjectCommand({ Bucket: bucket, Key: key, Body: Buffer.alloc(0), ContentLength: 0 })
212+
);
210213
}
211214

212215
export async function deleteKnownKeys(client: S3Client, bucket: string, keys: string[]) {

‎e2e/storage/upload.spec.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,8 @@ test.describe('Storage S3 — Upload', () => {
346346
const warning = page.getByRole('dialog', { name: 'Upload in progress' });
347347
await page.goBack();
348348
await expect(warning).toBeVisible();
349-
expect(page.url()).toBe(browseUrl);
349+
// SvelteKit restores the URL of a cancelled Back asynchronously.
350+
await expect(page).toHaveURL(browseUrl);
350351
await warning.getByRole('button', { name: 'Stay' }).click();
351352
await expect(warning).toBeHidden();
352353
await expect(page.getByRole('heading', { name: 'Upload', exact: true })).toBeVisible();

‎e2e/support/garage.ts‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,17 @@ async function ensureBucket(bucketName: string): Promise<string> {
152152
return existingId;
153153
}
154154

155-
const created = await adminPost('/v2/CreateBucket', { globalAlias: bucketName });
155+
let created: unknown;
156+
try {
157+
created = await adminPost('/v2/CreateBucket', { globalAlias: bucketName });
158+
} catch (err) {
159+
// Another worker may have created the bucket since the lookup above.
160+
const racedId = await findBucketId(bucketName);
161+
if (racedId) {
162+
return racedId;
163+
}
164+
throw err;
165+
}
156166
const createdId = readString(created, ['id', 'bucketId', 'bucket_id']);
157167

158168
if (createdId) {

0 commit comments

Comments
 (0)