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

chore(stepfunctions): add waitForAssertions to distributed-map assertions to wait for the expected resource state #30286

Merged
merged 4 commits into from
May 21, 2024

Conversation

colifran
Copy link
Contributor

@colifran colifran commented May 21, 2024

Reason for this change

Two assertions made in integ.distributed-map.ts are waiting on a specific resource state. The following waits for a state machine to be ACTIVE:

testCase.assertions
  .awsApiCall('StepFunctions', 'describeStateMachine', {
    stateMachineArn: stack.stateMachine.stateMachineArn,
  })
  .expect(ExpectedResult.objectLike({ status: 'ACTIVE' }));

The following wait for the state machine execution to be SUCCEEDED:

describe.expect(ExpectedResult.objectLike({
  status: 'SUCCEEDED',
}));

In the current format, the second assertion fails because the state machine execution is still running at the time the assertion is made. This causes the integ test to fail with the following error:

{
  "executionArn": "arn:aws:states:us-east-1:123456789012:execution:StateMachine2E01A3A5-OqZg4PaGWIUA:ecfc64d5-c20e-483b-a2ec-9ef8f82b2214",
  "input": "{}",
  "inputDetails": { ... },
  "name": "ecfc64d5-c20e-483b-a2ec-9ef8f82b2214",
  "redriveCount": 0,
  "redriveStatus": "NOT_REDRIVABLE",
  "redriveStatusReason": "Execution is RUNNING and cannot be redriven",
  "startDate": {},
  "stateMachineArn": "arn:aws:states:us-east-1:123456789012:stateMachine:StateMachine2E01A3A5-OqZg4PaGWIUA",
!! Expected SUCCEEDED but received RUNNING
  "status": "RUNNING",
  "traceHeader": "Root=1-664c0401-4504db7463bcd92c490e52bc;Parent=5ea37aeb46708a96;Sampled=0"
}

As a best practice, we should always ensure that assertions based on resource state have a waitForAssertions call to force the assertion to wait for the specific state to occur.

Description of changes

I added a waitForAssertions call to each assertion in this integ test that is waiting for a specific resource state. Each waitForAssertions call has the following waiter options:

  • A total timeout of 5 minutes, after which the assertion will fail.
  • A 10 second interval which will be used to check if the resource is in the expected state.

Description of how you validated changes

Re-ran the integ test and it succeeded.

Checklist


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

Signed-off-by: Francis <colifran@amazon.com>
@github-actions github-actions bot added the p2 label May 21, 2024
@aws-cdk-automation aws-cdk-automation requested a review from a team May 21, 2024 02:45
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label May 21, 2024
@colifran colifran changed the title chore(stepfunctions): add waitForAssertion to assertions to wait the expected response chore(stepfunctions): add waitForAssertion to assertions to wait for the expected response May 21, 2024
@colifran colifran changed the title chore(stepfunctions): add waitForAssertion to assertions to wait for the expected response chore(stepfunctions): add waitForAssertion to distributed-map assertions to wait for the expected response May 21, 2024
@aws-cdk-automation aws-cdk-automation added the pr/needs-maintainer-review This PR needs a review from a Core Team Member label May 21, 2024
@colifran colifran changed the title chore(stepfunctions): add waitForAssertion to distributed-map assertions to wait for the expected response chore(stepfunctions): add waitForAssertion to distributed-map assertions to wait for the expected resource state May 21, 2024
@colifran colifran changed the title chore(stepfunctions): add waitForAssertion to distributed-map assertions to wait for the expected resource state chore(stepfunctions): add waitForAssertions to distributed-map assertions to wait for the expected resource state May 21, 2024
Signed-off-by: Francis <colifran@amazon.com>
Signed-off-by: Francis <colifran@amazon.com>
Copy link
Contributor

@piradeepk piradeepk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm 🚀

Copy link
Contributor

mergify bot commented May 21, 2024

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation aws-cdk-automation removed the pr/needs-maintainer-review This PR needs a review from a Core Team Member label May 21, 2024
@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 7f80c8c
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify mergify bot merged commit 3a59d78 into main May 21, 2024
16 checks passed
@mergify mergify bot deleted the colifran/fix-distributed-map-assertion branch May 21, 2024 15:59
Copy link
Contributor

mergify bot commented May 21, 2024

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@colifran colifran self-assigned this May 21, 2024
mazyu36 pushed a commit to mazyu36/aws-cdk that referenced this pull request May 22, 2024
…rtions to wait for the expected resource state (aws#30286)

### Reason for this change

Two assertions made in `integ.distributed-map.ts` are waiting on a specific resource state. The following waits for a state machine to be `ACTIVE`:

```ts
testCase.assertions
  .awsApiCall('StepFunctions', 'describeStateMachine', {
    stateMachineArn: stack.stateMachine.stateMachineArn,
  })
  .expect(ExpectedResult.objectLike({ status: 'ACTIVE' }));
```

The following wait for the state machine execution to be `SUCCEEDED`:

```ts
describe.expect(ExpectedResult.objectLike({
  status: 'SUCCEEDED',
}));
```

In the current format, the second assertion fails because the state machine execution is still running at the time the assertion is made. This causes the integ test to fail with the following error:

```
{
  "executionArn": "arn:aws:states:us-east-1:123456789012:execution:StateMachine2E01A3A5-OqZg4PaGWIUA:ecfc64d5-c20e-483b-a2ec-9ef8f82b2214",
  "input": "{}",
  "inputDetails": { ... },
  "name": "ecfc64d5-c20e-483b-a2ec-9ef8f82b2214",
  "redriveCount": 0,
  "redriveStatus": "NOT_REDRIVABLE",
  "redriveStatusReason": "Execution is RUNNING and cannot be redriven",
  "startDate": {},
  "stateMachineArn": "arn:aws:states:us-east-1:123456789012:stateMachine:StateMachine2E01A3A5-OqZg4PaGWIUA",
!! Expected SUCCEEDED but received RUNNING
  "status": "RUNNING",
  "traceHeader": "Root=1-664c0401-4504db7463bcd92c490e52bc;Parent=5ea37aeb46708a96;Sampled=0"
}
```

As a best practice, we should always ensure that assertions based on resource state have a `waitForAssertions` call to force the assertion to wait for the specific state to occur.

### Description of changes

I added a `waitForAssertions` call to each assertion in this integ test that is waiting for a specific resource state. Each `waitForAssertions` call has the following waiter options:
- A total timeout of 5 minutes, after which the assertion will fail.
- A 10 second interval which will be used to check if the resource is in the expected state.

### Description of how you validated changes

Re-ran the integ test and it succeeded.

### Checklist
- [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
This was referenced May 27, 2024
atanaspam pushed a commit to atanaspam/aws-cdk that referenced this pull request Jun 3, 2024
…rtions to wait for the expected resource state (aws#30286)

### Reason for this change

Two assertions made in `integ.distributed-map.ts` are waiting on a specific resource state. The following waits for a state machine to be `ACTIVE`:

```ts
testCase.assertions
  .awsApiCall('StepFunctions', 'describeStateMachine', {
    stateMachineArn: stack.stateMachine.stateMachineArn,
  })
  .expect(ExpectedResult.objectLike({ status: 'ACTIVE' }));
```

The following wait for the state machine execution to be `SUCCEEDED`:

```ts
describe.expect(ExpectedResult.objectLike({
  status: 'SUCCEEDED',
}));
```

In the current format, the second assertion fails because the state machine execution is still running at the time the assertion is made. This causes the integ test to fail with the following error:

```
{
  "executionArn": "arn:aws:states:us-east-1:123456789012:execution:StateMachine2E01A3A5-OqZg4PaGWIUA:ecfc64d5-c20e-483b-a2ec-9ef8f82b2214",
  "input": "{}",
  "inputDetails": { ... },
  "name": "ecfc64d5-c20e-483b-a2ec-9ef8f82b2214",
  "redriveCount": 0,
  "redriveStatus": "NOT_REDRIVABLE",
  "redriveStatusReason": "Execution is RUNNING and cannot be redriven",
  "startDate": {},
  "stateMachineArn": "arn:aws:states:us-east-1:123456789012:stateMachine:StateMachine2E01A3A5-OqZg4PaGWIUA",
!! Expected SUCCEEDED but received RUNNING
  "status": "RUNNING",
  "traceHeader": "Root=1-664c0401-4504db7463bcd92c490e52bc;Parent=5ea37aeb46708a96;Sampled=0"
}
```

As a best practice, we should always ensure that assertions based on resource state have a `waitForAssertions` call to force the assertion to wait for the specific state to occur.

### Description of changes

I added a `waitForAssertions` call to each assertion in this integ test that is waiting for a specific resource state. Each `waitForAssertions` call has the following waiter options:
- A total timeout of 5 minutes, after which the assertion will fail.
- A 10 second interval which will be used to check if the resource is in the expected state.

### Description of how you validated changes

Re-ran the integ test and it succeeded.

### Checklist
- [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)

----

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

Comments on closed issues and PRs are hard for our team to see. If you need help, please open a new issue that references this one.

@aws aws locked as resolved and limited conversation to collaborators Jul 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
contribution/core This is a PR that came from AWS. p2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants