Skip to content

Commit

Permalink
test(client-s3): convert some read ops to waiters
Browse files Browse the repository at this point in the history
  • Loading branch information
kuhe committed Nov 5, 2024
1 parent 62ae71a commit f9937d8
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 14 deletions.
32 changes: 25 additions & 7 deletions clients/client-s3/test/e2e/S3.browser.e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { afterEach, beforeAll, beforeEach, describe, expect, test as it } from "

import { getIntegTestResources } from "../../../../tests/e2e/get-integ-test-resources";
import { getRuntimeConfig } from "../../src/runtimeConfig.browser";
import { S3 as S3Impl } from "../browser-build/browser-s3-bundle";
import { S3 as S3Impl, waitUntilObjectExists } from "../browser-build/browser-s3-bundle";
import { createBuffer } from "./helpers";

describe("@aws-sdk/client-s3", () => {
Expand All @@ -28,6 +28,18 @@ describe("@aws-sdk/client-s3", () => {
region,
credentials: fromNodeProviderChain(),
requestHandler: new FetchHttpHandler(),
logger: {
...console,
error(log: any) {
if ("clientName" in log) {
return;
}
console.error(log);
},
trace() {},
debug() {},
info() {},
},
})
) as unknown as S3;
});
Expand Down Expand Up @@ -209,11 +221,17 @@ describe("@aws-sdk/client-s3", () => {
expect(completeResult.$metadata.httpStatusCode).toEqual(200);

//validate the object is uploaded
const headResult = await client.headObject({
Bucket,
Key: multipartObjectKey,
});
expect(headResult.$metadata.httpStatusCode).toEqual(200);
const waiterState = await waitUntilObjectExists(
{
client,
maxWaitTime: 60,
},
{
Bucket,
Key: multipartObjectKey,
}
);
expect(waiterState.state).toEqual("SUCCESS");
});

it("should successfully create, abort, and list upload", async () => {
Expand Down Expand Up @@ -299,4 +317,4 @@ esfuture,29`;
}
});
});
});
}, 60_000);
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
import { S3 } from "@aws-sdk/client-s3";
import { S3, S3ClientConfig, waitUntilBucketExists, waitUntilBucketNotExists } from "@aws-sdk/client-s3";
import { GetCallerIdentityCommandOutput, STS } from "@aws-sdk/client-sts";
import { afterAll, beforeAll, describe, expect, test as it } from "vitest";

const testValue = "Hello S3 global client!";

describe("S3 Global Client Test", () => {
const regionConfigs = [
{ region: "us-east-1", followRegionRedirects: true },
{ region: "eu-west-1", followRegionRedirects: true },
{ region: "us-west-2", followRegionRedirects: true },
];
{ region: "us-east-1", followRegionRedirects: true } as S3ClientConfig,
{ region: "eu-west-1", followRegionRedirects: true } as S3ClientConfig,
{ region: "us-west-2", followRegionRedirects: true } as S3ClientConfig,
].map((config) => {
config.logger = {
...console,
error(log: any) {
if ("clientName" in log) {
return;
}
console.error(log);
},
trace() {},
debug() {},
info() {},
};
return config;
});
const s3Clients = regionConfigs.map((config) => new S3(config));
const stsClient = new STS({});

Expand All @@ -24,8 +38,18 @@ describe("S3 Global Client Test", () => {
beforeAll(async () => {
callerID = await stsClient.getCallerIdentity({});
bucketNames = regionConfigs.map((config) => `${callerID.Account}-${randId}-redirect-${config.region}`);
await Promise.all(bucketNames.map((bucketName, index) => deleteBucket(s3Clients[index], bucketName)));
await Promise.all(bucketNames.map((bucketName, index) => s3Clients[index].createBucket({ Bucket: bucketName })));
await Promise.all(
bucketNames.map(async (bucketName, index) => {
await deleteBucket(s3Clients[index], bucketName);
return waitUntilBucketNotExists({ client: s3Clients[index], maxWaitTime: 60 }, { Bucket: bucketName });
})
);
await Promise.all(
bucketNames.map(async (bucketName, index) => {
await s3Clients[index].createBucket({ Bucket: bucketName });
return waitUntilBucketExists({ client: s3Clients[index], maxWaitTime: 60 }, { Bucket: bucketName });
})
);
await Promise.all(bucketNames.map((bucketName, index) => s3Clients[index].headBucket({ Bucket: bucketName })));
});

Expand Down

0 comments on commit f9937d8

Please sign in to comment.