Skip to content

Commit f9937d8

Browse files
committed
test(client-s3): convert some read ops to waiters
1 parent 62ae71a commit f9937d8

File tree

2 files changed

+56
-14
lines changed

2 files changed

+56
-14
lines changed

clients/client-s3/test/e2e/S3.browser.e2e.spec.ts

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { afterEach, beforeAll, beforeEach, describe, expect, test as it } from "
55

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

1111
describe("@aws-sdk/client-s3", () => {
@@ -28,6 +28,18 @@ describe("@aws-sdk/client-s3", () => {
2828
region,
2929
credentials: fromNodeProviderChain(),
3030
requestHandler: new FetchHttpHandler(),
31+
logger: {
32+
...console,
33+
error(log: any) {
34+
if ("clientName" in log) {
35+
return;
36+
}
37+
console.error(log);
38+
},
39+
trace() {},
40+
debug() {},
41+
info() {},
42+
},
3143
})
3244
) as unknown as S3;
3345
});
@@ -209,11 +221,17 @@ describe("@aws-sdk/client-s3", () => {
209221
expect(completeResult.$metadata.httpStatusCode).toEqual(200);
210222

211223
//validate the object is uploaded
212-
const headResult = await client.headObject({
213-
Bucket,
214-
Key: multipartObjectKey,
215-
});
216-
expect(headResult.$metadata.httpStatusCode).toEqual(200);
224+
const waiterState = await waitUntilObjectExists(
225+
{
226+
client,
227+
maxWaitTime: 60,
228+
},
229+
{
230+
Bucket,
231+
Key: multipartObjectKey,
232+
}
233+
);
234+
expect(waiterState.state).toEqual("SUCCESS");
217235
});
218236

219237
it("should successfully create, abort, and list upload", async () => {
@@ -299,4 +317,4 @@ esfuture,29`;
299317
}
300318
});
301319
});
302-
});
320+
}, 60_000);

packages/middleware-sdk-s3/src/region-redirect-middleware.e2e.spec.ts

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,29 @@
1-
import { S3 } from "@aws-sdk/client-s3";
1+
import { S3, S3ClientConfig, waitUntilBucketExists, waitUntilBucketNotExists } from "@aws-sdk/client-s3";
22
import { GetCallerIdentityCommandOutput, STS } from "@aws-sdk/client-sts";
33
import { afterAll, beforeAll, describe, expect, test as it } from "vitest";
44

55
const testValue = "Hello S3 global client!";
66

77
describe("S3 Global Client Test", () => {
88
const regionConfigs = [
9-
{ region: "us-east-1", followRegionRedirects: true },
10-
{ region: "eu-west-1", followRegionRedirects: true },
11-
{ region: "us-west-2", followRegionRedirects: true },
12-
];
9+
{ region: "us-east-1", followRegionRedirects: true } as S3ClientConfig,
10+
{ region: "eu-west-1", followRegionRedirects: true } as S3ClientConfig,
11+
{ region: "us-west-2", followRegionRedirects: true } as S3ClientConfig,
12+
].map((config) => {
13+
config.logger = {
14+
...console,
15+
error(log: any) {
16+
if ("clientName" in log) {
17+
return;
18+
}
19+
console.error(log);
20+
},
21+
trace() {},
22+
debug() {},
23+
info() {},
24+
};
25+
return config;
26+
});
1327
const s3Clients = regionConfigs.map((config) => new S3(config));
1428
const stsClient = new STS({});
1529

@@ -24,8 +38,18 @@ describe("S3 Global Client Test", () => {
2438
beforeAll(async () => {
2539
callerID = await stsClient.getCallerIdentity({});
2640
bucketNames = regionConfigs.map((config) => `${callerID.Account}-${randId}-redirect-${config.region}`);
27-
await Promise.all(bucketNames.map((bucketName, index) => deleteBucket(s3Clients[index], bucketName)));
28-
await Promise.all(bucketNames.map((bucketName, index) => s3Clients[index].createBucket({ Bucket: bucketName })));
41+
await Promise.all(
42+
bucketNames.map(async (bucketName, index) => {
43+
await deleteBucket(s3Clients[index], bucketName);
44+
return waitUntilBucketNotExists({ client: s3Clients[index], maxWaitTime: 60 }, { Bucket: bucketName });
45+
})
46+
);
47+
await Promise.all(
48+
bucketNames.map(async (bucketName, index) => {
49+
await s3Clients[index].createBucket({ Bucket: bucketName });
50+
return waitUntilBucketExists({ client: s3Clients[index], maxWaitTime: 60 }, { Bucket: bucketName });
51+
})
52+
);
2953
await Promise.all(bucketNames.map((bucketName, index) => s3Clients[index].headBucket({ Bucket: bucketName })));
3054
});
3155

0 commit comments

Comments
 (0)