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

Timecop is freezing tests #245

Open
Turbo87 opened this issue Nov 15, 2017 · 13 comments
Open

Timecop is freezing tests #245

Turbo87 opened this issue Nov 15, 2017 · 13 comments
Labels

Comments

@Turbo87
Copy link
Member

Turbo87 commented Nov 15, 2017

We are using https://github.com/matteodepalo/ember-cli-timecop in a few component integration tests and until now this worked fine. We tried to convert those tests to use the new testing APIs, but now Timecop.freeze() seems to block the async render(...) call from continuing.

An issue similar to this has existed in the past where Backburner.js would not continue running when Date.now() is mocked and frozen, but was fixed by getting a reference to the Date object on startup and then using that reference instead of the temporary mocked global.

@Turbo87 Turbo87 added the bug label Nov 15, 2017
@Turbo87
Copy link
Member Author

Turbo87 commented Nov 15, 2017

Since #239 was not merged yet it seems that we are not actually using setTimeout() at all yet, so it must something else using it 🤔

@rwjblue
Copy link
Member

rwjblue commented Nov 15, 2017

@Turbo87 - Well, Ember.run.next ultimately does use setTimeout internally (and we are using run.next now).

@rwjblue
Copy link
Member

rwjblue commented Nov 15, 2017

If you have the time, could you put together a repo I could use for testing / experimenting with this?

@Turbo87
Copy link
Member Author

Turbo87 commented Nov 15, 2017

@rwjblue https://github.com/Turbo87/__timecop-issue

@Turbo87
Copy link
Member Author

Turbo87 commented Dec 12, 2017

Interestingly jamesarosen/Timecop.js#24 (comment) notes that:

Timecop doesn't modify the global setTimeout and setInterval implementations.

I updated the issue description to reflect this.

I'm wondering what is causing these freezes then 🤔

@rwjblue
Copy link
Member

rwjblue commented Dec 12, 2017

The issue is exactly what you mentioned in the initial description. BackburnerJS/backburner.js@a6fe19e changed Date.now to no longer be eagerly captured. The Ember.run.next's that we are calling (in setupContext and setupRenderingContext) create a scenario where settled() would never resolve (since it internally used Date.now() to determine if it should run our scheduled callback).

However, I also tested this with the changes from #239 and it does pass. I suspect that any "real world" scenario would still fail though. Essentially any usage of run.next or run.later in an app would cause this specific regression...

@Turbo87
Copy link
Member Author

Turbo87 commented Dec 12, 2017

How did this work before?

@Turbo87
Copy link
Member Author

Turbo87 commented Dec 12, 2017

Oh, I understand... BackburnerJS/backburner.js#264 🤔

@rwjblue
Copy link
Member

rwjblue commented Dec 12, 2017

Well, even with the same Ember version if you used the older style ember-qunit setup (e.g. moduleForComponent) nothing actually sets up a run.next / run.later so we just don't fall into this trap. tl;dr its a dozy 😭

@rwjblue
Copy link
Member

rwjblue commented Feb 11, 2018

Hmm, @Turbo87 I vaguely think that we discussed this in slack and you mentioned it was no longer an issue (or at least you had worked around it)?

@Turbo87
Copy link
Member Author

Turbo87 commented Feb 11, 2018

I'm not sure, but since #245 (comment) has a reproduction it should be relatively easy to verify whether this works now or not. In our real app I think we're using TimeCop.travel() now instead of .freeze() 🤔

@rwjblue
Copy link
Member

rwjblue commented Feb 11, 2018

kk, I'll try to pull it down and test...

@kiwi-josh
Copy link

We had/have a similar issue over at ember-mockdate-shim Ticketfly/ember-mockdate-shim#4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants