clock

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package clock abstracts time behind a Clock interface with a Real implementation for production and a manually advanced Fake for tests.

Why

Protocol code is full of time: the signing-time skew tolerance in cms, NotNow backoff in the command queue, SCEP challenge expiry, certificate validity checks in ca and push/apns, and DDM token timestamps. Testing those paths against the wall clock is slow and flaky, so the plan of record's package layout reserves this internal package and every time-sensitive package takes a Clock. Fake is safe for concurrent use so tests can advance it while a goroutine waits.

The package has no opinion on timers beyond After; scheduling, retry policy, and deadlines belong to the callers.

References

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Clock

type Clock interface {
	// Now returns the current time.
	Now() time.Time
	// Since returns the elapsed time since t.
	Since(t time.Time) time.Duration
	// After waits for the duration to elapse and then sends the current time
	// on the returned channel.
	After(d time.Duration) <-chan time.Time
}

Clock is the subset of the time package that the library depends on.

type Fake

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

Fake is a manually advanced Clock for tests. It is safe for concurrent use.

func NewFake

func NewFake(now time.Time) *Fake

NewFake returns a Fake clock set to now.

func (*Fake) Advance

func (f *Fake) Advance(d time.Duration)

Advance moves the clock forward by d and fires any waiters that are due.

func (*Fake) After

func (f *Fake) After(d time.Duration) <-chan time.Time

After implements Clock. The returned channel fires once Advance or Set moves the clock to or past now+d. A non-positive duration fires immediately.

func (*Fake) Now

func (f *Fake) Now() time.Time

Now implements Clock.

func (*Fake) Pending

func (f *Fake) Pending() int

Pending reports how many After waiters have not fired yet.

func (*Fake) Set

func (f *Fake) Set(t time.Time)

Set moves the clock to t (forward or backward) and fires any waiters that are due.

func (*Fake) Since

func (f *Fake) Since(t time.Time) time.Duration

Since implements Clock.

type Real

type Real struct{}

Real is a Clock backed by the time package.

func (Real) After

func (Real) After(d time.Duration) <-chan time.Time

After implements Clock.

func (Real) Now

func (Real) Now() time.Time

Now implements Clock.

func (Real) Since

func (Real) Since(t time.Time) time.Duration

Since implements Clock.

Jump to

Keyboard shortcuts

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