-
Notifications
You must be signed in to change notification settings - Fork 4k
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
fix(core): Durations in the expected unit are not tested for integer-ness #20742
Conversation
…g set to a duration of fractional minutes and added unit tests to aws-events/test/schedule.test.ts
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.
Hey Parker,
Thanks for the submit! What I'm going to say in my review might sound a little harsh and abrasive and challenging. I will be asking "Why" a lot. Know it's intended with all ❤️ and I'm just trying to focus your thought processes, and make sure you think about what you're trying to achieve while doing something!
(Also, the messages below sound generic and repetitive and that's because they are. I'm experimenting with standard responses to PRs because--believe it or not--a lot of people keep forgetting to do the same things over and over again and I'm starting to get tired of typing the same replies over and over again 🙃)
Please make sure that your PR title confirms to the conventional commit standard (fix
, feat
, chore
) and that it is written in a style that will reflect correctly in the change log (See Contributing Guide, Pull Requests)
Please make sure that your PR body describes the problem the PR is solving, and the design approach and alternatives considered. Explain why the PR solves the problem. A link to an issue is helpful, but does not replace an explanation of your thought process (See Contributing Guide, Pull Requests)
if (duration.toSeconds() % 60 !== 0) { | ||
throw new Error(`'Duration must be a whole number of minutes, Duration provided was ${duration.toMinutes()} minutes'`); | ||
} |
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.
Why this? You didn't really explain the motivation for the change, but as far as I can tell on line 40
below we do duration.toMinutes({ integral: true })
, which will throw if the duration is not convertible to a whole number of minutes.
You just added a different exception that will throw if the duration is not convertible to a whole number of minutes.
It looks like you're trading out one error for another, so: why?
- Is the original error message not good enough? If so: is that maybe something we should be clearing up instead? Can we/should we change the original error message?
- If that's your thought process, and you considered and rejected updating the error produced by
Duration.toMinutes()
, then that would be helpful to include in your PR description, because it would give me insight into things you have considered and rejected, and will help me understand why you came up with the solution you came up with.
- If that's your thought process, and you considered and rejected updating the error produced by
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.
The original issue asks for a change to the documentation (to explain that the duration has to be a whole number of minutes, because this was apparently a surprise to the reporter), not for a code change.
Was it a conscious decision to forego the documentation update? Did you misread the original bug report?
…te() in aws-events/schedule.ts, and fixed the documentation for Schedule and EventPattern in aws-events/rule.ts
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.
Please also still adjust the PR on the GitHub website (edit the title and body).
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.
Hey @scanlonp :). This is looking good! Also, sorry I’m on mobile so no clue how this review will turn out. I suggest you take a look at how our merged PRs are titled and emulate that. Also I’d link you the GitHub docs for this but since I’m on mobile I’ll tell you: GitHub recognizes when you say something like “closes #xxxxx” and will link that issue to be closed when this PR is merged. You should change your PR description to have that phrase rather than “addresses” so that GitHub will pick it up.
Also, take a look at why the build is failing and see if you can fix it. You should probably start with a local ‘yarn build’ in ‘events’ and see if there are errors there.
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.
I think this PR somewhat misunderstands the problem. There isn't actually a bug here. The function behaves as we expect it to but we're not providing clear documentation on the fact that we expect certain failures.
@@ -19,6 +23,8 @@ export abstract class Schedule { | |||
|
|||
/** | |||
* Construct a schedule from an interval and a time unit | |||
* | |||
* Rates cannot be defined in fractions of minutes and cannot be 0 |
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.
This is really the only place where we need a documentation update. It should be clear that the rate cannot be more granular than a minute. I tend to think instead of saying what cannot be done, we should be more explicit about how this should be used. The user can do Duration.whateverUnit, but if we don't get an integer of greater than 0 when converting it into minutes, we throw an error. I'll leave the specific wording up to you.
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.
I will update it here to be more positive in what the user should do rather than what they are prevented from doing.
I think the test is wrong. 1.1 seconds doesn't look like valid input, I don't know why that was chosen. |
Pull request has been modified.
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 CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
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). |
…ness (aws#20742) ---- Converting from a type to itself would not check the integral flag and simply return the current duration amount rather than throwing an error if the amount converted to was fractional. Commands such as `toSeconds()` or `toMinutes()` had the same behavior since they leverage `convert()`. `Duration.minutes(0.5).toMinutes();` previously would not throw an error, but `Duration.seconds(30).toMinutes();` would. `Duration.minutes(0.5).toMinutes();` will now throw an error while `Duration.minutes(0.5).toMinutes({ integral: false});` will not. fix(@aws-cdk/aws-events/schedule.ts): `rate()` now correctly catches if a duration is defined in fractions of a minute. The root cause was the use of `Duration.toMinutes()` in `rate()`. Now all rates defined with durations must be in whole minutes. docs: this limitation on rates is highlighted more clearly in the documentation for aws-events/schedule.ts and aws-events/rule.ts. This closes aws#17814. ### All Submissions: * [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) ### Adding new Unconventional Dependencies: * [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-new-unconventional-dependencies) ### New Features * [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)? * [ ] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)? *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Converting from a type to itself would not check the integral flag and simply return the current duration amount rather than throwing an error if the amount converted to was fractional.
Commands such as
toSeconds()
ortoMinutes()
had the same behavior since they leverageconvert()
.Duration.minutes(0.5).toMinutes();
previously would not throw an error, butDuration.seconds(30).toMinutes();
would.Duration.minutes(0.5).toMinutes();
will now throw an error whileDuration.minutes(0.5).toMinutes({ integral: false});
will not.fix(@aws-cdk/aws-events/schedule.ts):
rate()
now correctly catches if a duration is defined in fractions of a minute. The root cause was the use ofDuration.toMinutes()
inrate()
. Now all rates defined with durations must be in whole minutes.docs: this limitation on rates is highlighted more clearly in the documentation for aws-events/schedule.ts and aws-events/rule.ts.
This closes #17814.
All Submissions:
Adding new Unconventional Dependencies:
New Features
yarn integ
to deploy the infrastructure and generate the snapshot (i.e.yarn integ
without--dry-run
)?By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license