process.hrtime is not mocked by timer #159

Closed
seriousManual opened this Issue Jul 13, 2012 · 5 comments

Projects

None yet

2 participants

@seriousManual

process.hrtime() (link) provides the elapsed time in a high resolution (nanoseconds) on node.

when using the sinon timer hrtime is not mocked so that tests that rely on clock.tick will fail.

@cjohansen
Collaborator

Should it be stubbed, though? If so, the clock needs the ability to tick nanoseconds as well, e.g. clock.tick(1, 23) (to match the hrtime API). Thoughts?

@seriousManual

i think one problem is that process.hrtime doesn't provide an absolute time value but an relative one. so the main use case is for measuring timespans between intervals. don't know how good that fits into the sinon concept...

@cjohansen
Collaborator

I don't think the relative aspect matters. It could always start at 0. I'll keep this open, and add it, but I think it will not be stubbed by default. However, it could be enabled for

sinon.useFakeTimers("setTimeout", "clearTimeout", "hrtime");
@seriousManual

sounds good!

@cjohansen
Collaborator

This will not be part of the fake timers in Sinon - I just don't see enough use cases. If you really need to stub this, use sinon.stub(process, hrtime).returns(500).

@cjohansen cjohansen closed this Nov 17, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment