A fake TimerService, for unit tests that do not use a real
kernel. You can make time pass by calling advanceTo(when), or one
timeStep at a time by calling tick().
advanceTo() merely schedules a wakeup: the actual
handlers (in the code under test) are invoked several turns
later. Some zoe/etc tests want to poll for the consequences of
those invocations. The best approach is to get an appropriate
Promise from your code-under-test, wait for it to fire, and then
poll. But some libraries do not offer this convenience, especially
when they use internal "fire and forget" actions.
To support those tests, the manual timer accepts a
eventLoopIteration option. If provided, each call to tick()
will wait for all triggered activity to complete before
returning. That doesn't mean the wake() handler's result promise
has fired; it just means there are no settled Promises still trying
to execute their callbacks.
The following will wait for all such Promise activity to finish
before returning from tick():
A fake TimerService, for unit tests that do not use a real kernel. You can make time pass by calling
advanceTo(when)
, or onetimeStep
at a time by callingtick()
.advanceTo()
merely schedules a wakeup: the actual handlers (in the code under test) are invoked several turns later. Some zoe/etc tests want to poll for the consequences of those invocations. The best approach is to get an appropriate Promise from your code-under-test, wait for it to fire, and then poll. But some libraries do not offer this convenience, especially when they use internal "fire and forget" actions.To support those tests, the manual timer accepts a
eventLoopIteration
option. If provided, each call totick()
will wait for all triggered activity to complete before returning. That doesn't mean thewake()
handler's result promise has fired; it just means there are no settled Promises still trying to execute their callbacks.The following will wait for all such Promise activity to finish before returning from
tick()
:eventLoopIteration = () => new Promise(setImmediate); mt = buildManualTimer(log, startTime, { eventLoopIteration })
tickN(count)
callstick()
multiple times, awaiting each oneThe first argument is called to log 'tick' events, which might help with "golden transcript" -style tests to distinguish tick boundaries