luci: go.chromium.org/luci/common/clock/testclock Index | Files

package testclock

import "go.chromium.org/luci/common/clock/testclock"

Index

Package Files

context.go testclock.go testtimer.go

Variables

var TestRecentTimeLocal = time.Date(2016, time.February, 3, 4, 5, 6, 7, time.Local)

TestRecentTimeLocal is like TestTimeLocal, but in the recent past.

var TestRecentTimeUTC = time.Date(2016, time.February, 3, 4, 5, 6, 7, time.UTC)

TestRecentTimeUTC is like TestTimeUTC, but in the recent past.

var TestTimeLocal = time.Date(1, time.February, 3, 4, 5, 6, 7, time.Local)

TestTimeLocal is an arbitrary time point in the 'Local' time zone for testing.

It corresponds to a negative Unix timestamp, so it might be inappropriate for some tests. Use 'TestRecentTimeLocal' for more "real" test time in this case.

var TestTimeUTC = time.Date(1, time.February, 3, 4, 5, 6, 7, time.UTC)

TestTimeUTC is an arbitrary time point in UTC for testing.

It corresponds to a negative Unix timestamp, so it might be inappropriate for some tests. Use 'TestRecentTimeUTC' for more "real" test time in this case.

func GetTags Uses

func GetTags(t clock.Timer) []string

GetTags returns the tags associated with the specified timer. If the timer has no tags, an empty slice (nil) will be returned.

func HasTags Uses

func HasTags(t clock.Timer, first string, tags ...string) bool

HasTags tests if a given timer has the same tags.

type TestClock Uses

type TestClock interface {
    clock.Clock

    // Set sets the test clock's time.
    Set(time.Time)

    // Add advances the test clock's time.
    Add(time.Duration)

    // SetTimerCallback is a goroutine-safe method to set an instance-wide
    // callback that is invoked when any timer begins.
    SetTimerCallback(TimerCallback)
}

TestClock is a Clock interface with additional methods to help instrument it.

func New Uses

func New(now time.Time) TestClock

New returns a TestClock instance set at the specified time.

func UseTime Uses

func UseTime(ctx context.Context, now time.Time) (context.Context, TestClock)

UseTime instantiates a TestClock and returns a Context that is configured to use that clock, as well as the instantiated clock.

type TimerCallback Uses

type TimerCallback func(time.Duration, clock.Timer)

TimerCallback that can be invoked when a timer has been set. This is useful for sychronizing state when testing.

Package testclock imports 5 packages (graph) and is imported by 10 packages. Updated 2018-12-19. Refresh now. Tools for package owners.