clocktest

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 23, 2026 License: MIT Imports: 4 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package clocktest provides a manually driven util.Clock for tests: time only moves when the test calls Advance or Set, so polling, backoff and debounce run without sleeps.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Clock

type Clock struct {
	// contains filtered or unexported fields
}

Clock is a fake util.Clock. The zero value is not usable; use New.

func New

func New(start time.Time) *Clock

New returns a fake clock standing at start.

func (*Clock) Advance

func (c *Clock) Advance(d time.Duration)

Advance moves the clock forward by d and fires every timer and ticker that falls due, in time order. Tickers fire once per period passed; like time.Ticker, ticks are dropped while the channel is full.

func (*Clock) BlockUntil

func (c *Clock) BlockUntil(n int)

BlockUntil blocks until at least n timers or tickers are active, so a test can wait for a goroutine to reach its next wait before advancing the clock.

func (*Clock) NewTicker

func (c *Clock) NewTicker(d time.Duration) util.Ticker

NewTicker returns a ticker firing every d of fake time.

func (*Clock) NewTimer

func (c *Clock) NewTimer(d time.Duration) util.Timer

NewTimer returns a timer that fires once the clock passed now+d.

func (*Clock) Now

func (c *Clock) Now() time.Time

Now returns the fake time.

func (*Clock) Set

func (c *Clock) Set(t time.Time)

Set moves the clock to t (forward only; an earlier t only sets the time, as a clock jump).

func (*Clock) Waiters

func (c *Clock) Waiters() int

Waiters returns the number of active timers and tickers.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL