Title: test_runner: mock setInterval uses wrong interval after first time · Issue #50381 · nodejs/node · GitHub
Open Graph Title: test_runner: mock setInterval uses wrong interval after first time · Issue #50381 · nodejs/node
X Title: test_runner: mock setInterval uses wrong interval after first time · Issue #50381 · nodejs/node
Description: Version main Platform Linux s7 5.15.0-69-generic #76-Ubuntu SMP Fri Mar 17 17:19:29 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux Subsystem test What steps will reproduce the bug? When a mocked setInterval timer is triggered, the timers runAt ...
Open Graph Description: Version main Platform Linux s7 5.15.0-69-generic #76-Ubuntu SMP Fri Mar 17 17:19:29 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux Subsystem test What steps will reproduce the bug? When a mocked setInterv...
X Description: Version main Platform Linux s7 5.15.0-69-generic #76-Ubuntu SMP Fri Mar 17 17:19:29 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux Subsystem test What steps will reproduce the bug? When a mocked setInterv...
Opengraph URL: https://github.com/nodejs/node/issues/50381
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"test_runner: mock setInterval uses wrong interval after first time","articleBody":"### Version\n\nmain\n\n### Platform\n\nLinux s7 5.15.0-69-generic #76-Ubuntu SMP Fri Mar 17 17:19:29 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux\n\n### Subsystem\n\ntest\n\n### What steps will reproduce the bug?\n\nWhen a mocked `setInterval` timer is triggered, the timers runAt time is updated for the next time it should run [here](https://github.com/nodejs/node/blob/4f5db8b26d906f1cbe9f6a9ac2028b0f7ad88c91/lib/internal/test_runner/mock/mock_timers.js#L625). However , the increment is actually always 1, since the boolean flag `isInterval` is stored in the timer [here](https://github.com/nodejs/node/blob/4f5db8b26d906f1cbe9f6a9ac2028b0f7ad88c91/lib/internal/test_runner/mock/mock_timers.js#L268)\r\n\r\nPull request incoming.\r\n\r\n```js\r\ntest(\"setInterval uses the wrong interval\", async (t) =\u003e {\r\n t.mock.timers.enable({ apis: [\"setInterval\"] });\r\n const fn = t.mock.fn();\r\n\r\n setInterval(fn, 1000);\r\n\r\n assert.strictEqual(fn.mock.callCount(), 0);\r\n\r\n t.mock.timers.tick(1000);\r\n\r\n assert.strictEqual(fn.mock.callCount(), 1);\r\n\r\n for (let i = 0; i \u003c 999; ++i) {\r\n t.mock.timers.tick(1);\r\n }\r\n\r\n assert.strictEqual(fn.mock.callCount(), 1);\r\n});\r\n```\r\n\r\nfails with:\r\n\r\n```\r\n❯ ~/src/libs/node/node index.mjs\r\n﹣ aborting setTimeout clears wrong timer (2.795504ms) # SKIP\r\n﹣ aborting setTimeout after timer is already triggered clear wrong timer (0.20311ms) # SKIP\r\n✖ setInterval uses the wrong interval (24.795796ms)\r\n AssertionError [ERR_ASSERTION]: Expected values to be strictly equal:\r\n \r\n 1000 !== 1\r\n \r\n at TestContext.\u003canonymous\u003e (file:///home/mfischer/src/tests/node-mock-timers/index.mjs:72:10)\r\n at Test.runInAsyncScope (node:async_hooks:206:9)\r\n at Test.run (node:internal/test_runner/test:631:25)\r\n at Test.processPendingSubtests (node:internal/test_runner/test:374:18)\r\n at Test.postRun (node:internal/test_runner/test:715:19)\r\n at Test.run (node:internal/test_runner/test:673:12)\r\n at async Test.processPendingSubtests (node:internal/test_runner/test:374:7) {\r\n generatedMessage: true,\r\n code: 'ERR_ASSERTION',\r\n actual: 1000,\r\n expected: 1,\r\n operator: 'strictEqual'\r\n }\r\n```\n\n### How often does it reproduce? Is there a required condition?\n\nAlways\n\n### What is the expected behavior? Why is that the expected behavior?\n\nsetInterval should use the correct interval\n\n### What do you see instead?\n\nsetInverval always uses interval 1 after first time\n\n### Additional information\n\n_No response_","author":{"url":"https://github.com/mika-fischer","@type":"Person","name":"mika-fischer"},"datePublished":"2023-10-25T08:04:45.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/50381/node/issues/50381"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:06c617bd-68a7-f29f-813d-e0a630f3e831 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D648:AA1C4:EDA5DC:1399577:6969A432 |
| html-safe-nonce | 765039d59364e8e09f33c1024fac324b728bdf30d9b8d2620b84f43a961a3ff8 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENjQ4OkFBMUM0OkVEQTVEQzoxMzk5NTc3OjY5NjlBNDMyIiwidmlzaXRvcl9pZCI6IjY5MjY0OTg5OTU1OTI4NjQ4MTkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 755b57b4e00bb7d8c2fc144c9a14319d6f617ee8de7eadc6a41cc24758abd111 |
| hovercard-subject-tag | issue:1960797186 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/nodejs/node/50381/issue_layout |
| twitter:image | https://opengraph.githubassets.com/4335ec7ce6b00f647333d7f625793bdd6ba0dddf42f5d749f16258d3738a9b88/nodejs/node/issues/50381 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/4335ec7ce6b00f647333d7f625793bdd6ba0dddf42f5d749f16258d3738a9b88/nodejs/node/issues/50381 |
| og:image:alt | Version main Platform Linux s7 5.15.0-69-generic #76-Ubuntu SMP Fri Mar 17 17:19:29 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux Subsystem test What steps will reproduce the bug? When a mocked setInterv... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mika-fischer |
| hostname | github.com |
| expected-hostname | github.com |
| None | 24c4c97a2d520cb286b35e1a4c22d7a4df3c26a2fa28dd7cdf0e65db327b4de7 |
| turbo-cache-control | no-preview |
| go-import | github.com/nodejs/node git https://github.com/nodejs/node.git |
| octolytics-dimension-user_id | 9950313 |
| octolytics-dimension-user_login | nodejs |
| octolytics-dimension-repository_id | 27193779 |
| octolytics-dimension-repository_nwo | nodejs/node |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 27193779 |
| octolytics-dimension-repository_network_root_nwo | nodejs/node |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 124667f43168afb6c9c03b7c02eb5b1d2e1be3d9 |
| ui-target | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width