GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — test_runner: Add Date to the supported mock APIs by khaosdoctor · Pull Request #48638 · nodejs/node Conversation
|
|
Review requested:
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
I don't think Date.now should be passed as a param while enabling timers as it's not a timer. IMHO In this first version Date.now should advance in time when some .tick call happens cc @nodejs/test_runner |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
I think it's a timer in the sense that's an API to manipulate or count time in general. But I can see your point too, it can be confusing, I took as an inspiration the last PR and Sinon's fake timers API, this last one also mocks not only the But IMO it kinda makes sense to be here, I would expect an API to manipulate date to be in the fake timers implementation as an user.
Regarding this, it's already happening in this implementation, tick is advancing the |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Mocking |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Yeah I thought so later on, it wouldn't make a lot of sense 😄 thanks for clarifying! Will add this to the next steps |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
a83b9f9 introduces a problem and a question. When From here I think we have two options:
Any thoughts? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
| this.#now = 0; | ||
| } else if (this.#isValidDateWithGetTime(args[0])) { | ||
| // First argument is the initial time as Date | ||
| this.#now = args[0].getTime(); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
do we mean to call .getTime() on the argument, or should this instead be:
| this.#now = args[0].getTime(); | |
| this.#now = DatePrototypeGetTime(args[0]); |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
It's the intended one, if the first argument is an instance of Date then we will call the getTime method on it to get the timestamp
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
right but if it's an actual Date object - which may not be instanceof Date - you don't want to rely on the presence of Date.prototype.getTime at runtime.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
| #isEnabled = false; | ||
| #currentTimer = 1; | ||
| #now = DateNow(); | ||
| #now = 0; |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
#now should be DateNow unless it's changed by .setTime
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
But that differs from the implementation from fake-timers. If the intention is to be close to that API then we wouldn't be able to start it as DateNow, however, I'm not against that too. I think it's worth a discussion with @nodejs/test_runner
On my side I think the pros is that you can start the Date object without actually setting anything on it, as opposed to having to set the time at any given new fake timer instance because otherwise you'd have Jan 1, 1970. Which also can be a pro to some people as it's more explicit to what time is the initial time.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
| p.then(common.mustCall((result) => { | ||
| assert.ok(result); | ||
| })); | ||
| p.then( |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
same here
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
I think runAll shouldn't affect Date.now as it's just releasing all pending operations so option 1 is the best IMHO |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There is a third option here which is to have a property in the |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I don't understand the rationale not to progress the clock date whenever it should happen (e.g by 20ms if a 20ms setTimeout delayed has run)? I think this was the sinon/jest behavior and I don't think anyone ever asked for anything different? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I was under the impression that when Date was mocked, time never advanced except manually by the user. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
As far as I remember from our code in fake-timers we always progress Date/performance.now when we progress timers. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Alright! I think I'll work on them today up to the end and we can implement that version, I also think it's the best solution, then we can have a base v1 ready :) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@ljharb @ErickWendel @benjamingr I think I'm done with this version 😄 if you could please review it 🚀 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Other than my comments LGTM |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
@khaosdoctor I've retried it one more time, if it fails again I suggest you rebase on top of main. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@RafaelGSS Now it seems to be good to go! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Cool!
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Commit Queue failed- Loading data for nodejs/node/pull/48638 ✔ Done loading data for nodejs/node/pull/48638 ----------------------------------- PR info ------------------------------------ Title test_runner: Add Date to the supported mock APIs (#48638) Author Lucas Santos (@khaosdoctor) Branch khaosdoctor:test_runner/introduce_improve_fake_timers -> nodejs:main Labels semver-minor, notable-change, author ready, needs-ci, commit-queue-squash, test_runner Commits 3 - test_runner: add Date to the supported mock APIs - Apply suggestions from code review - Apply suggestions from code review Committers 1 - Lucas Santos PR-URL: https://github.com/nodejs/node/pull/48638 Reviewed-By: Benjamin Gruenbaum Reviewed-By: Moshe Atlow Reviewed-By: Erick Wendel Reviewed-By: Rafael Gonzaga ------------------------------ Generated metadata ------------------------------ PR-URL: https://github.com/nodejs/node/pull/48638 Reviewed-By: Benjamin Gruenbaum Reviewed-By: Moshe Atlow Reviewed-By: Erick Wendel Reviewed-By: Rafael Gonzaga -------------------------------------------------------------------------------- ⚠ Commits were pushed since the last approving review: ⚠ - test_runner: add Date to the supported mock APIs ⚠ - Apply suggestions from code review ⚠ - Apply suggestions from code review ℹ This PR was created on Sun, 02 Jul 2023 19:29:31 GMT ✔ Approvals: 4 ✔ - Benjamin Gruenbaum (@benjamingr) (TSC): https://github.com/nodejs/node/pull/48638#pullrequestreview-1655247395 ✔ - Moshe Atlow (@MoLow) (TSC): https://github.com/nodejs/node/pull/48638#pullrequestreview-1630117150 ✔ - Erick Wendel (@erickwendel): https://github.com/nodejs/node/pull/48638#pullrequestreview-1536004400 ✔ - Rafael Gonzaga (@RafaelGSS) (TSC): https://github.com/nodejs/node/pull/48638#pullrequestreview-1665791940 ✔ Last GitHub CI successful ℹ Last Full PR CI on 2023-10-10T12:43:52Z: https://ci.nodejs.org/job/node-test-pull-request/54632/ ⚠ Commits were pushed after the last Full PR CI run: ⚠ - test_runner: add Date to the supported mock APIs ⚠ - Apply suggestions from code review ⚠ - Apply suggestions from code review - Querying data for job/node-test-pull-request/54632/ ✔ Last Jenkins CI successful -------------------------------------------------------------------------------- ✔ Aborted `git node land` session in /home/runner/work/node/node/.ncuhttps://github.com/nodejs/node/actions/runs/6527901651 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
RSLGTM
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
signed-off-by: Lucas Santos <[email protected]>
Co-authored-by: Antoine du Hamel <[email protected]>
Co-authored-by: Antoine du Hamel <[email protected]>
Co-authored-by: Antoine du Hamel <[email protected]>
|
Merging @anonrig changes in the tests that includes some of them (including the ones failing here) as flaky to check if this will pass |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Landed in 45a0b15 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
OMG FINALLY ⭐ |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Thanks @anonrig for the flaky PRs! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.