Documentation
¶
Overview ¶
Package crontest tests an app's crons: Run runs one by name with its dependencies, and Clock is a virtual clock to test schedules with — time stands still until the test moves it.
clock := crontest.NewClock(time.Date(2026, 1, 5, 6, 59, 0, 0, time.UTC)) app := web.New(web.CronClock(clock), web.Provide(NewStore)) app.Start(ctx) defer app.Stop(ctx) clock.WaitTimers(1) // the scheduler waits for its tick clock.Advance(time.Minute) // 07:00: the cron runs crontest.Wait(app) // and is done
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Clock ¶
type Clock struct {
// contains filtered or unexported fields
}
Clock is a virtual cron.Clock: Now is what the test set, and timers fire when Advance or Set moves time past them.
func (*Clock) Set ¶
Set moves the clock to t, firing the timers due in order. A scheduler makes its next timer only after the previous one fired: to see every tick, move the clock one tick at a time, waiting for the timers between (WaitTimers).
func (*Clock) WaitTimers ¶
WaitTimers waits until n timers are waiting — the scheduler is waiting for its crons' next ticks — for at most 5 seconds, reporting whether they are.