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

runToLastAsync doing infinite loop when now is specified to setup clock #450

Closed
guillaumeduboc opened this issue Nov 19, 2022 · 0 comments · Fixed by #451
Closed

runToLastAsync doing infinite loop when now is specified to setup clock #450

guillaumeduboc opened this issue Nov 19, 2022 · 0 comments · Fixed by #451

Comments

@guillaumeduboc
Copy link
Contributor

While working on vitest-dev/vitest#2209 I have an issue with runToLastAsync doing an infinite loop
Below you can find a minimal test to reproduce the issue

We understand you have a problem and are in a hurry, but please provide us with some info to make it much more likely for your issue to be understood, worked on and resolved quickly.

  • FakeTimers version : 9.1.2

  • Environment : MACOS

  • Example URL : a minimial reproduction test

  • Other libraries you are using: none

What did you expect to happen?
An infinite loop shouldn't be possible and this test shouldn't break

What actually happens
This test times out

How to reproduce
Here is a minimal test to reproduce the issue

        it("new timers created from promises cannot cause an infinite loop when a date is given", function () {
            this.clock = FakeTimers.createClock(Date.now());
            const test = this;
            const spy = sinon.spy();
            const recursiveCallback = function () {
                global.Promise.resolve().then(function () {
                    test.clock.setTimeout(recursiveCallback, 0);
                });
            };

            this.clock.setTimeout(recursiveCallback, 0);
            this.clock.setTimeout(spy, 100);

            return this.clock.runToLastAsync().then(function () {
                assert.isTrue(spy.called);
            });
        });

The error for this test is

Capture d’écran 2022-11-19 à 01 08 23

guillaumeduboc added a commit to guillaumeduboc/fake-timers that referenced this issue Nov 19, 2022
fatso83 pushed a commit that referenced this issue Nov 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant