Skip to content
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

(integ-tests): awsApiCall() cannot be used with same service and action #23049

Closed
yamatatsu opened this issue Nov 23, 2022 · 7 comments
Closed
Labels
@aws-cdk/integ-tests bug This issue is a bug. effort/small Small work item – less than a day of effort p2

Comments

@yamatatsu
Copy link
Contributor

yamatatsu commented Nov 23, 2022

Describe the bug

Now, awsApiCall() cannot be used twice with same service and action.

Because AwsApiCall's id is made by string literal as following:

`AwsApiCall${service}${api}`

at here.

Expected Behavior

To be able to use with same service and action greater than twice.

Current Behavior

An error is occured.

Error message:

/aws-cdk/node_modules/constructs/lib/construct.js:334
            throw new Error(`There is already a Construct with name '${childName}' in ${typeName}${name.length > 0 ? ' [' + name + ']' : ''}`);
            ^

Error: There is already a Construct with name 'AwsApiCallLambdainvoke' in Stack [DeployAssert]
    at Node.addChild (/aws-cdk/node_modules/constructs/lib/construct.js:334:19)
    at new Node (/aws-cdk/node_modules/constructs/lib/construct.js:29:21)
    at new Construct (/aws-cdk/node_modules/constructs/lib/construct.js:368:21)
    at new ApiCallBase (/aws-cdk/packages/@aws-cdk/integ-tests/lib/assertions/api-call-base.js:13:9)
    at new AwsApiCall (/aws-cdk/packages/@aws-cdk/integ-tests/lib/assertions/sdk.js:17:9)

Reproduction Steps

import { App, Stack } from 'aws-cdk-lib';
import { Queue } from 'aws-cdk-lib/aws-sqs';
import { ExpectedResult, IntegTest } from '@aws-cdk/integ-tests-alpha';

const app = new App();
const stackA = new Stack(app, 'represent-aws-cdk-integ-tests-bug-stack-a');
const queueA = new Queue(stackA, 'queue-a');
const stackB = new Stack(app, 'represent-aws-cdk-integ-tests-bug-stack-b');
const queueB = new Queue(stackB, 'queue-b');

const integ = new IntegTest(app, 'Integ', { testCases: [stackA, stackB] });

for (const queue of [queueA, queueB]) {
  const response = integ.assertions.awsApiCall('SQS', 'sendMessage', {
    QueueUrl: queue.queueUrl,
    MessageBody: 'foo'
  });
  response.provider.addToRolePolicy({
    Effect: 'Allow',
    Action: ['sqs:SendMessage'],
    Resource: [queue.queueArn],
  });
  response.expect(ExpectedResult.objectLike({}));
}

app.synth();

See https://github.com/yamatatsu/represent-aws-cdk-integ-tests-bug .

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

v2.51.1

Framework Version

No response

Node.js Version

v18.12.1

OS

mac (apple silicon)

Language

Typescript

Language Version

3.9.10

Other information

No response

@yamatatsu yamatatsu added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Nov 23, 2022
@pahud
Copy link
Contributor

pahud commented Nov 23, 2022

Thank you @yamatatsu !! It seems to make sense if we are allowed to pass an id parameter to it. Do you have any suggested solution for it? I am making this a P2 and your PR would be highly appreciated.

@pahud pahud added p2 effort/small Small work item – less than a day of effort and removed needs-triage This issue or PR still needs to be triaged. labels Nov 23, 2022
@yamatatsu
Copy link
Contributor Author

@pahud
Sorry for the late reply.
The solution I found is useing hash with the argument parameters as here.
I'll create PR in this year!

@yamatatsu yamatatsu reopened this Dec 5, 2022
@github-actions
Copy link

github-actions bot commented Dec 5, 2022

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

@misterjoshua
Copy link
Contributor

Related to #22043

mergify bot pushed a commit that referenced this issue Oct 10, 2023
This PR resolves errors in the integration test library when users run identical assertions multiple times.

This change ensures that each use of `awsApiCall`, `httpApiCall`, and `invokeFunction` has a unique identifier, even when multiple identical assertions are used in the same context. We introduced a `uniqueAssertionId` function in the `DeployAssert` construct that maintains backward compatibility with the old id rendering scheme, but prevents the use of conflicting construct ids by tracking the usage of ids and differentiating them where there's a conflict.

Closes #22043, #23049

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@misterjoshua
Copy link
Contributor

@yamatatsu a change referencing this issue was merged and released. Is your issue resolved?

@colifran
Copy link
Contributor

Closed by #27380

Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/integ-tests bug This issue is a bug. effort/small Small work item – less than a day of effort p2
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants