-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(cli): hotswapping is slow for many resources deployed at once (#1…
…9081) In the `LazyListStackResources` class, we were incorrectly caching the results of the ListStackResources CloudFormation API call. This resulted in executing redundant calls, and very visibly impacted the performance of hotswapping when the Stack included many resources. In manual testing, this change brought down deployment time of a large Stack from 80 to 7 seconds. Closes #19021 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
- Loading branch information
Showing
2 changed files
with
41 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
packages/aws-cdk/test/api/lazy-list-stack-resources.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import * as AWS from 'aws-sdk'; | ||
import { LazyListStackResources } from '../../lib/api/evaluate-cloudformation-template'; | ||
import { MockSdk } from '../util/mock-sdk'; | ||
|
||
describe('Lazy ListStackResources', () => { | ||
test('correctly caches calls to the CloudFormation API', async () => { | ||
// GIVEN | ||
const listStackResMock: jest.Mock<AWS.CloudFormation.ListStackResourcesOutput, AWS.CloudFormation.ListStackResourcesInput[]> = jest.fn(); | ||
const mockSdk = new MockSdk(); | ||
mockSdk.stubCloudFormation({ | ||
listStackResources: listStackResMock, | ||
}); | ||
listStackResMock.mockReturnValue({ | ||
StackResourceSummaries: [], | ||
NextToken: undefined, | ||
}); | ||
const res = new LazyListStackResources(mockSdk, 'StackName'); | ||
|
||
// WHEN | ||
void res.listStackResources(); | ||
void res.listStackResources(); | ||
void res.listStackResources(); | ||
const result = await res.listStackResources(); | ||
|
||
// THEN | ||
expect(result.length).toBe(0); | ||
expect(listStackResMock).toHaveBeenCalledTimes(1); | ||
}); | ||
}); |