express 4.10.2 issue with sinon fake timers
Problem
When calling Sinon.JS's `useFakeTimers` with the most recent version of Express, requests sent to the app aren't answered. This is caused by the commit titled "Correctly invoke async router callback asynchronously", which changed line 186 of `lib/router/index.js` from `return done(layerError)` to `setImmediate(done, layerError)`. When using fake timers, functions run using `setImmediate` don't execute until one explicitly ticks forward the clock. It could be argued this isn't really a problem with Express, and rather the solution is to be sure to tick whenever one issues a request to the app. However, it's not entirely clear to me how this could be done, since one would have to know when Express got to that `setImmediate` call and only then tick. Further, even if it is possible, it's doubtful many existing tests do this, meaning this breaks a lot of existing code. Presumably this is also a problem with any other framework that manipulates `setImmediate`, not just Sinon.
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Solution: express 4.10.2 issue with sinon fake timers
I'm not similar with what Sinon.JS even is, but if that is the comment that broke it, it's 100% not a bug in Express. Express simply stopped releasing Zalgo in that comment, i.e. we fixed the behavior of our async callback to be _always async_ instead of _sometimes async_.
Trust Score
1 verification
- 1
I'm not similar with what Sinon.JS even is, but if that is the comment that brok
I'm not similar with what Sinon.JS even is, but if that is the comment that broke it, it's 100% not a bug in Express. Express simply stopped releasing Zalgo in that comment, i.e. we fixed the behavior of our async callback to be _always async_ instead of _sometimes async_.
Validation
Resolved in expressjs/express GitHub issue #2447. Community reactions: 0 upvotes.
Verification Summary
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep