clock

package
v5.61.0 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: Apache-2.0 Imports: 10 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 clock is the source of the current time for muster's timers that measure elapsed time: the reconnect backoff of a remote MCPServer, the orchestrator's retry and health-probe ticks, the aggregator's capability poll and the age of its core catalogue.

In production Now is time.Now. When MUSTER_TEST_CLOCK names a Unix socket, the process serves a control endpoint on it (StartControl) through which the integration test harness advances the clock: Now jumps forward by the offset and every Ticker whose next tick has become due fires at once. A scenario about a two-minute backoff cap or a five-minute catalogue age then runs on the production schedule in milliseconds, instead of on intervals shortened through environment knobs. The offset is process-wide and only ever grows, as wall time does.

Index

Constants

View Source
const EnvControlSocket = "MUSTER_TEST_CLOCK"

EnvControlSocket is the environment variable that selects the clock's control socket. Set by the integration test harness for every instance it runs; unset in production, where nothing can move the clock.

Variables

This section is empty.

Functions

func Advance

func Advance(d time.Duration) (time.Duration, error)

Advance moves the clock forward by d and returns the total offset. Every Ticker is woken, so a tick that has become due fires at once. A negative d is refused: the clock only moves forward.

func Now

func Now() time.Time

Now returns the current time as muster sees it: the system time plus the offset the clock has been advanced by.

func Offset

func Offset() time.Duration

Offset returns how far the clock has been advanced past the system time.

func RemoteAdvance

func RemoteAdvance(path string, d time.Duration) (time.Duration, error)

RemoteAdvance advances the clock of the process serving its control endpoint on path by d and returns that process's total offset.

func RemoteOffset

func RemoteOffset(path string) (time.Duration, error)

RemoteOffset returns the total offset of the process serving its control endpoint on path.

func Since

func Since(t time.Time) time.Duration

Since returns the time elapsed since t on this clock.

func StartControl

func StartControl() (stop func(), err error)

StartControl serves the clock's control endpoint on the Unix socket named by MUSTER_TEST_CLOCK and returns the function that stops it and removes the socket file. With the variable unset it serves nothing and returns a no-op. A socket file a previous life of the process left behind is replaced.

func Until

func Until(t time.Time) time.Duration

Until returns the duration until t on this clock.

Types

type Ticker

type Ticker struct {
	// C is the channel on which the ticks are delivered.
	C <-chan time.Time
	// contains filtered or unexported fields
}

Ticker delivers ticks at intervals of d on this clock, like time.Ticker, and also when Advance moves the clock past its next tick. A receiver that has not taken the previous tick is not sent a second one.

func NewTicker

func NewTicker(d time.Duration) *Ticker

NewTicker returns a Ticker whose first tick is due d from now.

func (*Ticker) Stop

func (t *Ticker) Stop()

Stop turns off the ticker. No more ticks are sent; C is not closed.

Jump to

Keyboard shortcuts

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