{"action":"created","issue":{"url":"https://api.github.com/repos/sinonjs/sinon/issues/960","labels_url":"https://api.github.com/repos/sinonjs/sinon/issues/960/labels{/name}","comments_url":"https://api.github.com/repos/sinonjs/sinon/issues/960/comments","events_url":"https://api.github.com/repos/sinonjs/sinon/issues/960/events","html_url":"https://github.com/sinonjs/sinon/issues/960","id":125289894,"number":960,"title":"stubbing setImmediate by default leads to undesirable behavior ","user":{"login":"kevinburkeshyp","id":10735057,"avatar_url":"https://avatars.githubusercontent.com/u/10735057?v=3","gravatar_id":"","url":"https://api.github.com/users/kevinburkeshyp","html_url":"https://github.com/kevinburkeshyp","followers_url":"https://api.github.com/users/kevinburkeshyp/followers","following_url":"https://api.github.com/users/kevinburkeshyp/following{/other_user}","gists_url":"https://api.github.com/users/kevinburkeshyp/gists{/gist_id}","starred_url":"https://api.github.com/users/kevinburkeshyp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kevinburkeshyp/subscriptions","organizations_url":"https://api.github.com/users/kevinburkeshyp/orgs","repos_url":"https://api.github.com/users/kevinburkeshyp/repos","events_url":"https://api.github.com/users/kevinburkeshyp/events{/privacy}","received_events_url":"https://api.github.com/users/kevinburkeshyp/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-01-06T23:46:11Z","updated_at":"2016-01-07T10:57:25Z","closed_at":null,"body":"I noticed this while trying to figure out why stubbing the system time caused csv writing to fail. It turns out that library had a `setImmediate` call that was blocking: https://github.com/C2FO/fast-csv/blob/master/lib/extended.js#L18\r\n\r\nIt seems like there are a bunch of libraries that rely on `setImmediate` for innocuous things, and that faking `setImmediate` leads to unexpected behavior in all of them:\r\n\r\n- request: https://github.com/sinonjs/sinon/issues/484\r\n- async: https://github.com/caolan/async/issues/609\r\n- express.js: https://github.com/strongloop/express/issues/2447\r\n- bluebird: http://stackoverflow.com/q/31403818/329700\r\n- co: https://github.com/sinonjs/sinon/issues/527\r\n\r\nMaybe it's unreasonable to expect that stubbing the system time does not cause csv writing to fail? In this case it's particularly difficult to track down, because in Javascript you can't just hit `ctrl+c` and get a stack trace showing you what went wrong. It took about 90 minutes just to identify what part of the code was freezing, and then to understand why sinon was responsible.\r\n\r\nI'm not sure what the fix should be, but it seems to be affecting a lot of libraries, and at least one of them responded by creating its own version of `setImmediate` that can't be mangled with. \r\n\r\nIf the answer is I should be calling `useFakeTimers(0, \"Date\")`, maybe that should be the default? Maybe that fits better with my/people's expectations of how the world behaves?"},"comment":{"url":"https://api.github.com/repos/sinonjs/sinon/issues/comments/169629356","html_url":"https://github.com/sinonjs/sinon/issues/960#issuecomment-169629356","issue_url":"https://api.github.com/repos/sinonjs/sinon/issues/960","id":169629356,"user":{"login":"mroderick","id":20321,"avatar_url":"https://avatars.githubusercontent.com/u/20321?v=3","gravatar_id":"","url":"https://api.github.com/users/mroderick","html_url":"https://github.com/mroderick","followers_url":"https://api.github.com/users/mroderick/followers","following_url":"https://api.github.com/users/mroderick/following{/other_user}","gists_url":"https://api.github.com/users/mroderick/gists{/gist_id}","starred_url":"https://api.github.com/users/mroderick/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mroderick/subscriptions","organizations_url":"https://api.github.com/users/mroderick/orgs","repos_url":"https://api.github.com/users/mroderick/repos","events_url":"https://api.github.com/users/mroderick/events{/privacy}","received_events_url":"https://api.github.com/users/mroderick/received_events","type":"User","site_admin":false},"created_at":"2016-01-07T10:57:24Z","updated_at":"2016-01-07T10:57:24Z","body":"> I'm not sure what the fix should be, but it seems to be affecting a lot of libraries, and at least one of them responded by creating its own version of setImmediate that can't be mangled with.\r\n\r\nThat is the recommended solution for when you're using setTimeout, setImmediate for effect of getting a new call stack (and not for controlling time). \r\n\r\nhttps://github.com/taylorhakes/promise-polyfill/pull/15"}}