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

fix(NODE-3116): reschedule unreliable async interval first #3006

Merged
merged 3 commits into from Nov 5, 2021
Merged

Conversation

durran
Copy link
Member

@durran durran commented Oct 18, 2021

Description

When there is an unreliable clock we force async intervals to reschedule immediately.

What is changing?

The async interval check for negative clock times, like potentially AWS lambda, is moved to the first check so that we can potentially reschedule instead of just returning as was done previously.

Is there new documentation needed for these changes?

No.

Double check the following

  • Ran npm run check:lint script
  • Self-review completed using the steps outlined here
  • PR title follows the correct format: <type>(NODE-xxxx)<!>: <description>
  • Changes are covered by tests
  • New TODOs have a related JIRA ticket

@dariakp dariakp self-requested a review October 18, 2021 16:46
@dariakp dariakp added the Primary Review In Review with primary reviewer, not yet ready for team's eyes label Oct 18, 2021
@@ -140,8 +140,11 @@ describe('utils', function () {

// needs to happen on the third call because `wake` checks
// the `currentTime` at the beginning of the function
// The value of now() is not actually negative in the case of
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you explain how this test works to test the "immediately schedule if the clock is unreliable"? I am having trouble following what the marks array is tracking. Also, the original test had an unexpected return time (i.e., a time in the past), why is that no longer a legitimate test case? Which clause in the utils code was it hitting originally? And does it definitely hit the new clause now? How do we differentiate between "executeAndReschedule" and just "reschedule"?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's a weird way of testing but I wanted to stay in line with the other tests in there. The marks are basically "marking" the time interval in which the repeatable callback was executed, and I admit it's not the clearest way to test. I changed this test because the title of the test, which was intended to test this specific scenario, wasn't actually executing the code path that was under test. The value simply being less than now was simply hitting the first block and returning. Once I switched to force the value to be negative, then the test failed until I moved the check we actually wanted to run up to be the first code branch.

Copy link
Contributor

Choose a reason for hiding this comment

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

My concern is that none of these tests are meaningfully asserting on the actual intent of the code: for example, if you comment out the entire block under the logic that is supposed to debounce multiple calls, the test above this one still passes, which tells me that we can't be confident that the current fix doesn't actually break some other desired behavior. I am worried that the current test structure is based on a flawed approach: we need to make sure that these tests actually isolate the test conditions, which means that if we are using just a sequence tracking the callback calls, we need to either make sure the sequence is unique to the expected code path - and make it clear why that sequence is unique to the expect path - or we need to make sure we are also asserting on what we expect to not happen.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah I guess it's probably better to find a more meaningful way to test this and refactor the other tests as well.

@durran durran requested a review from dariakp October 20, 2021 17:30
@dariakp dariakp added wip and removed Primary Review In Review with primary reviewer, not yet ready for team's eyes labels Nov 2, 2021
@dariakp
Copy link
Contributor

dariakp commented Nov 2, 2021

Note: we should decide if we still want to target 4.1 for this or update to 4.2

@durran durran changed the base branch from 4.1 to main November 4, 2021 09:42
@durran durran added Primary Review In Review with primary reviewer, not yet ready for team's eyes and removed wip labels Nov 4, 2021
@durran durran force-pushed the NODE-3116 branch 2 times, most recently from c9c586a to c5e1ec0 Compare November 4, 2021 12:26
@dariakp dariakp added Team Review Needs review from team and removed Primary Review In Review with primary reviewer, not yet ready for team's eyes labels Nov 5, 2021
@dariakp dariakp requested a review from nbbeeken November 5, 2021 13:50
@durran durran merged commit 33886a7 into main Nov 5, 2021
@durran durran deleted the NODE-3116 branch November 5, 2021 14:35
ljhaywar pushed a commit that referenced this pull request Nov 9, 2021
* fix(NODE-3116): reschedule unreliable async interval first

Co-authored-by: Daria Pardue <daria.pardue@mongodb.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Team Review Needs review from team
Projects
None yet
3 participants