Skip to content
This repository was archived by the owner on Aug 15, 2024. It is now read-only.

Version bumps causing problems with fake timers in tests. #20

Closed
gnarf opened this issue Mar 5, 2015 · 16 comments
Closed

Version bumps causing problems with fake timers in tests. #20

gnarf opened this issue Mar 5, 2015 · 16 comments

Comments

@gnarf
Copy link

gnarf commented Mar 5, 2015

The new version bump for process 0.10.x is causing sinon fake timers + bluebird + webpack to make all bluebird promises "freeze" (because it's now using setTimeout instead of the other method it used to (mutation/etc selection process had in 0.8)

Having a hard time figuring how how to undo this problem because webpack itself lists the dep on node-libs-browser to be ~0.4.0 and the bump here is definitely causing problems in all of our test suites that use sinon + bluebird.

@gnarf
Copy link
Author

gnarf commented Mar 5, 2015

Basically doing this:

cd node_modules/webpack/node_modules/node-libs-browser ; npm i [email protected]

Is how I'm fixing it right now, and it works.

@sokra
Copy link
Member

sokra commented Mar 5, 2015

This should propably be fixed in simon or bluebird... Am I right?

@gnarf
Copy link
Author

gnarf commented Mar 5, 2015

Perhaps, but I think this is an artifact coming from the "browserifying" of it. The process.nextTick implementation in process could hold onto the "real" setTimeout and call it. Or maybe bluebird could do a better job of detecting fake node "process" and revert back to using mutation observers? CC @petkaantonov

@gnarf
Copy link
Author

gnarf commented Mar 5, 2015

For reference https://github.com/defunctzombie/node-process/blob/master/browser.js#L28 is the cause of the problem -- the old version in 0.8.0 used a much more clever way that avoided calling the sinon fake timer here: https://github.com/defunctzombie/node-process/blob/v0.8.0/browser.js#L14

@petkaantonov
Copy link

maybe bluebird could do a better job of detecting fake node "process"

I don't think this is the issue given https://github.com/petkaantonov/bluebird/blob/master/src/util.js#L280-L281

@benjamingr
Copy link

Also worth mentioning you can always tell bluebird explicitly how to schedule via Promise.setScheduler - although like Petka said it's not bluebird misdetecting here.

@gnarf
Copy link
Author

gnarf commented Mar 5, 2015

@petkaantonov then why does installing process 0.8.0 again inside the webpack deps fix the problem?

@sokra
Copy link
Member

sokra commented Mar 5, 2015

@gnarf can you provide a test case so we can play around with it?

@petkaantonov
Copy link

I didn't look into the real issue here, I was just pointing out that recent versions of bluebird check for authentic process object that cannot be faked without access to native v8 api.

@gnarf
Copy link
Author

gnarf commented Mar 5, 2015

Oh - when did that check get added? Perhaps I'm still behind on bluebird somewhere.

FWIW this test case fails:

/* global sinon */
require('script!sinon/pkg/sinon');

describe.only('faketime', function() {
  var timers;
  beforeEach(function() {
    timers = sinon.useFakeTimers();
  });
  afterEach(function() {
    timers.restore();
  });
  it('can resolve a promise', function() {
    return require('bluebird').resolve();
  });
});

@petkaantonov
Copy link

It's in 2.9.6+

@sokra
Copy link
Member

sokra commented Mar 5, 2015

sinon fake timers do stop process.nextTick until you call timers.tick(ms), if I get the documentation correctly...

@gnarf
Copy link
Author

gnarf commented Mar 5, 2015

Except that same test passes with process 0.8.0 instead of 0.10.0 --- it also passes with bluebird 2.9.13+ - so I think I know the answer -- dependency hunt time to figure out what isn't up to date with bluebird

Sorry to take this up as an issue here instead of in bluebird! Thanks for the support @petkaantonov and @sokra

@gnarf gnarf closed this as completed Mar 5, 2015
@KidkArolis
Copy link

I'm running into the same issue with when.js + webpack + sinon.useFakeTimers - all promises seem to break. Does bluebird do something extra to detect it's not actually a node env @gnarf ?

@gnarf
Copy link
Author

gnarf commented Apr 24, 2015

Make sure to use latest bluebird?
On Apr 24, 2015 10:37 AM, "Karolis Narkevicius" [email protected]
wrote:

I'm running into the same issue with when.js + webpack +
sinon.useFakeTimers - all promises seem to break. Does bluebird do
something extra to detect it's not actually a node env @gnarf
https://github.com/gnarf ?


Reply to this email directly or view it on GitHub
#20 (comment)
.

@gnarf
Copy link
Author

gnarf commented Apr 24, 2015

Sorry, misread... Look at the scheduler code in bluebird. The node process
object has a special to string value so you can detect it is node
On Apr 24, 2015 10:38 AM, "Corey Frang" [email protected] wrote:

Make sure to use latest bluebird?
On Apr 24, 2015 10:37 AM, "Karolis Narkevicius" [email protected]
wrote:

I'm running into the same issue with when.js + webpack +
sinon.useFakeTimers - all promises seem to break. Does bluebird do
something extra to detect it's not actually a node env @gnarf
https://github.com/gnarf ?


Reply to this email directly or view it on GitHub
#20 (comment)
.

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

No branches or pull requests

5 participants