diff --git a/packages/core/src/test/shared/awsClientBuilderV3.test.ts b/packages/core/src/test/shared/awsClientBuilderV3.test.ts index dc577f33bce..7cff0dd2f23 100644 --- a/packages/core/src/test/shared/awsClientBuilderV3.test.ts +++ b/packages/core/src/test/shared/awsClientBuilderV3.test.ts @@ -4,6 +4,7 @@ */ import sinon from 'sinon' import assert from 'assert' +import http from 'http' import { version } from 'vscode' import { getClientId } from '../../shared/telemetry/util' import { FakeMemento } from '../fakeExtensionContext' @@ -32,6 +33,7 @@ import { Credentials, MetadataBearer, MiddlewareStack } from '@aws-sdk/types' import { oneDay } from '../../shared/datetime' import { ConfiguredRetryStrategy } from '@smithy/util-retry' import { StandardRetryStrategy } from '@smithy/util-retry' +import { DescribeSessionsCommand, SSMClient } from '@aws-sdk/client-ssm' describe('AwsClientBuilderV3', function () { let builder: AWSClientBuilderV3 @@ -318,6 +320,38 @@ describe('recordErrorTelemetry', function () { }) }) +describe('connection reuse', function () { + it('reuses connections', async function () { + const port = 3000 + const server = http.createServer((req, rsp) => { + rsp.writeHead(200, { 'Content-Type': 'application/json' }) + rsp.end(JSON.stringify({ message: 'success' })) + }) + try { + server.listen(port, () => {}) + const config = { + region: 'us-east-1', + endpoint: `http://localhost:${port}`, + // requestHandler: new NodeHttpHandler({ + // httpAgent: new Agent({ keepAlive: true }), + // }), + } + const client = new SSMClient(config) + const requests: http.IncomingMessage[] = [] + server.on('request', (req) => { + requests.push(req) + }) + await client.send(new DescribeSessionsCommand({ State: 'Active' })) + await client.send(new DescribeSessionsCommand({ State: 'Active' })) + + assert.strictEqual(requests[0].headers.connection, 'keep-alive') + assert.strictEqual(requests.length, 1) + } finally { + server.close() + } + }) +}) + class MockCredentialsShim implements CredentialsShim { public constructor( public credentials: Credentials,