Skip to content

Commit 84b2b62

Browse files
authored
test(client-kinesis): aggregate HTTP/2 sessions across all endpoint pools (#8181)
1 parent ceb9aee commit 84b2b62

1 file changed

Lines changed: 24 additions & 29 deletions

File tree

clients/client-kinesis/test/Kinesis.e2e.spec.ts

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { CreateStreamCommand, Kinesis } from "@aws-sdk/client-kinesis";
1+
import { Kinesis } from "@aws-sdk/client-kinesis";
22
import { NodeHttp2Handler } from "@aws-sdk/config/requestHandler";
3-
import { getEndpointFromInstructions } from "@smithy/core/endpoints";
43
import { type MetadataBearer } from "@smithy/types";
54
import { afterAll, beforeAll, describe, expect, test as it } from "vitest";
65

@@ -23,13 +22,6 @@ describe("@aws-sdk/client-kinesis", () => {
2322
return (client.config.requestHandler as any).connectionManager?.debug?.();
2423
};
2524

26-
/**
27-
* The endpoint the client resolves to, used as the connection pool key.
28-
* Resolved from the client config instead of being hardcoded, so the test
29-
* follows the client's configured region/endpoint.
30-
*/
31-
let endpoint: string;
32-
3325
async function setup() {
3426
await client.createStream({ StreamName: STREAM_NAME, ShardCount: SHARD_COUNT });
3527
let status = "";
@@ -120,15 +112,19 @@ describe("@aws-sdk/client-kinesis", () => {
120112
* ]
121113
* ```
122114
*/
115+
116+
/**
117+
* Aggregates sessions across every connection pool the client opened.
118+
*
119+
* A client can resolve to more than one endpoint depending on the operation,
120+
* so the connection manager may hold multiple pools. We total the sessions
121+
* across all of them rather than keying off a single endpoint.
122+
*/
123123
function getSessions(state: any) {
124-
return state?.[endpoint]?.sessions ?? [];
124+
return Object.values(state ?? {}).flatMap((pool: any) => pool?.sessions ?? []);
125125
}
126126

127127
beforeAll(async () => {
128-
// Resolve the endpoint the same way the SDK does at request time.
129-
const { url } = await getEndpointFromInstructions({}, CreateStreamCommand, client.config);
130-
endpoint = url.toString();
131-
132128
connectionManagerStates.initial = debug();
133129
await setup();
134130

@@ -185,26 +181,25 @@ describe("@aws-sdk/client-kinesis", () => {
185181
* If debugging this test, get a picture of the connection states
186182
* at each step by logging this object.
187183
*/
188-
console.log(JSON.stringify(connectionManagerStates, null, 2));
184+
// console.log(JSON.stringify(connectionManagerStates, null, 2));
189185
expect(connectionManagerStates.initial).toEqual({});
190186

191187
expect(getSessions(connectionManagerStates.requestsFinished)).not.toEqual([]);
192-
expect(connectionManagerStates.requestsFinished).toMatchObject({
193-
[endpoint]: {
194-
sessions: getSessions(connectionManagerStates.requestsFinished).map(() => sessionType),
195-
},
196-
});
188+
for (const session of getSessions(connectionManagerStates.requestsFinished)) {
189+
expect(session).toMatchObject(sessionType);
190+
}
197191

198192
expect(getSessions(connectionManagerStates.secondBatchRequestsFinished)).not.toEqual([]);
199-
expect(connectionManagerStates.secondBatchRequestsFinished).toMatchObject({
200-
[endpoint]: {
201-
sessions: getSessions(connectionManagerStates.secondBatchRequestsFinished).map(() => sessionType),
202-
},
203-
});
204-
205-
expect(connectionManagerStates.idle[endpoint]).toEqual({
206-
sessions: [],
207-
});
193+
for (const session of getSessions(connectionManagerStates.secondBatchRequestsFinished)) {
194+
expect(session).toMatchObject(sessionType);
195+
}
196+
197+
// Every pool the client opened should have drained to zero sessions once idle.
198+
const idlePools = Object.values(connectionManagerStates.idle ?? {});
199+
expect(idlePools.length).toBeGreaterThan(0);
200+
for (const pool of idlePools) {
201+
expect((pool as any).sessions).toEqual([]);
202+
}
208203

209204
expect(connectionManagerStates.destroyed).toEqual({});
210205
});

0 commit comments

Comments
 (0)