From f9937d8649368e6b801cbba166c2c89e2bff0d6b Mon Sep 17 00:00:00 2001 From: George Fu Date: Tue, 5 Nov 2024 16:03:12 +0000 Subject: [PATCH] test(client-s3): convert some read ops to waiters --- .../client-s3/test/e2e/S3.browser.e2e.spec.ts | 32 ++++++++++++---- .../region-redirect-middleware.e2e.spec.ts | 38 +++++++++++++++---- 2 files changed, 56 insertions(+), 14 deletions(-) diff --git a/clients/client-s3/test/e2e/S3.browser.e2e.spec.ts b/clients/client-s3/test/e2e/S3.browser.e2e.spec.ts index 2e64bb7ceb2f6..d071a34391ff7 100644 --- a/clients/client-s3/test/e2e/S3.browser.e2e.spec.ts +++ b/clients/client-s3/test/e2e/S3.browser.e2e.spec.ts @@ -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", () => { @@ -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; }); @@ -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 () => { @@ -299,4 +317,4 @@ esfuture,29`; } }); }); -}); +}, 60_000); diff --git a/packages/middleware-sdk-s3/src/region-redirect-middleware.e2e.spec.ts b/packages/middleware-sdk-s3/src/region-redirect-middleware.e2e.spec.ts index 78ef2589452d4..56cf2e48473c5 100644 --- a/packages/middleware-sdk-s3/src/region-redirect-middleware.e2e.spec.ts +++ b/packages/middleware-sdk-s3/src/region-redirect-middleware.e2e.spec.ts @@ -1,4 +1,4 @@ -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"; @@ -6,10 +6,24 @@ 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({}); @@ -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 }))); });