-
Notifications
You must be signed in to change notification settings - Fork 122
fix(toolkit-lib): throttled final event poll fails a successful deploy #1941
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
117 changes: 117 additions & 0 deletions
117
packages/@aws-cdk/toolkit-lib/test/api/deployments/deploy-stack-event-poll-failures.test.ts
This file contains hidden or 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,117 @@ | ||
| import type { CloudFormationStackArtifact } from '@aws-cdk/cloud-assembly-api'; | ||
| import { deployStack, destroyStack } from '../../../lib/api/deployments/deploy-stack'; | ||
| import type { DeployStackOptions as DeployStackApiOptions } from '../../../lib/api/deployments/deploy-stack'; | ||
| import { CloudFormationStackDiagnoser } from '../../../lib/api/diagnosing/stack-diagnoser'; | ||
| import { NoBootstrapStackEnvironmentResources } from '../../../lib/api/environment'; | ||
| import { StackArtifactSourceTracer } from '../../../lib/api/source-tracing/private/stack-source-tracing'; | ||
| import { testStack } from '../../_helpers/assembly'; | ||
| import { FakeCloudFormation } from '../../_helpers/fake-aws/fake-cloudformation'; | ||
| import { advanceTime } from '../../_helpers/fake-time'; | ||
| import { | ||
| mockCloudFormationClient, | ||
| mockResolvedEnvironment, | ||
| MockSdk, | ||
| MockSdkProvider, | ||
| restoreSdkMocksToDefault, | ||
| } from '../../_helpers/mock-sdk'; | ||
| import { TestIoHost } from '../../_helpers/test-io-host'; | ||
|
|
||
| const ioHost = new TestIoHost(); | ||
| const ioHelper = ioHost.asHelper('deploy'); | ||
|
|
||
| const FAKE_STACK = testStack({ | ||
| stackName: 'withouterrors', | ||
| template: { | ||
| Resources: { | ||
| MyResource: { | ||
| Type: 'Test::Resource::Type', | ||
| Properties: { | ||
| Bar: 'Bar', | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| let sdk: MockSdk; | ||
| let sdkProvider: MockSdkProvider; | ||
| const fakeCfn = new FakeCloudFormation(); | ||
|
|
||
| beforeEach(() => { | ||
| fakeCfn.reset(); | ||
| ioHost.clear(); | ||
|
|
||
| sdkProvider = new MockSdkProvider(); | ||
| sdk = new MockSdk(); | ||
|
|
||
| restoreSdkMocksToDefault(); | ||
| fakeCfn.installUsingAwsMock(mockCloudFormationClient); | ||
|
|
||
| jest.useFakeTimers(); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| jest.useRealTimers(); | ||
| jest.restoreAllMocks(); | ||
| }); | ||
|
|
||
| function standardDeployStackArguments(stack: CloudFormationStackArtifact = FAKE_STACK): DeployStackApiOptions { | ||
| const resolvedEnvironment = mockResolvedEnvironment(); | ||
| return { | ||
| stack, | ||
| sdk, | ||
| sdkProvider, | ||
| resolvedEnvironment, | ||
| envResources: new NoBootstrapStackEnvironmentResources(resolvedEnvironment, sdk, ioHelper), | ||
| diagnoser: new CloudFormationStackDiagnoser({ | ||
| sdk, | ||
| sourceTracer: new StackArtifactSourceTracer(stack), | ||
| ioHelper, | ||
| topLevelStackHierarchicalId: stack.hierarchicalId, | ||
| }), | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * Throttle every stack event read, leaving the rest of the CloudFormation API working | ||
| */ | ||
| function throttleStackEventReads() { | ||
| const realClient = sdk.cloudFormation(); | ||
| jest.spyOn(sdk, 'cloudFormation').mockReturnValue({ | ||
| ...realClient, | ||
| describeStackEvents: () => Promise.reject(Object.assign(new Error('Rate exceeded'), { name: 'Throttling' })), | ||
| }); | ||
| } | ||
|
|
||
| describe.each(['change-set', 'direct'] as const)('a successful %s deployment', (method) => { | ||
| test('is not failed by a throttled stack event poll', async () => { | ||
| // GIVEN - reading stack events fails throughout, including the final poll in monitor.stop() | ||
| throttleStackEventReads(); | ||
|
|
||
| // WHEN | ||
| const result = await advanceTime(deployStack({ | ||
| ...standardDeployStackArguments(), | ||
| deploymentMethod: { method }, | ||
| }, ioHelper)); | ||
|
|
||
| // THEN - the deployment succeeded, and the final poll failure was only reported | ||
| expect(result).toMatchObject({ type: 'did-deploy-stack' }); | ||
| ioHost.expectMessage({ level: 'warn', containing: 'the event log may be incomplete' }); | ||
| }); | ||
| }); | ||
|
|
||
| test('a successful destroy is not failed by a throttled stack event poll', async () => { | ||
| // GIVEN | ||
| fakeCfn.createStackSync({ StackName: 'withouterrors' }); | ||
| throttleStackEventReads(); | ||
|
|
||
| // WHEN | ||
| const result = await advanceTime(destroyStack({ | ||
| stack: FAKE_STACK, | ||
| sdk, | ||
| }, ioHelper)); | ||
|
|
||
| // THEN | ||
| expect(result.stackArn).toBeDefined(); | ||
| ioHost.expectMessage({ level: 'warn', containing: 'the event log may be incomplete' }); | ||
| }); |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can probably do better here in terms of the message, maybe just use the error name in the default warning and emit the full error as debug message that can be enabled using
-v. We can tell the users about this flag in the message as well.