eventclock

package
v0.26.1 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Fake

type Fake struct {
	baseclocktest.FakePassiveClock
	// contains filtered or unexported fields
}

Fake is one whose time does not pass implicitly but rather is explicitly set by invocations of its SetTime method. Each Fake has an associated GoRoutineCounter that is used to track associated activity. For the EventAfterDuration and EventAfterTime methods, the clock itself counts the start and stop of the EventFunc and the client is responsible for counting any suspend and resume internal to the EventFunc. The Sleep method must only be invoked from a goroutine that is counted in that GoRoutineCounter.

func NewFake

func NewFake(t time.Time, fuzz time.Duration, r *rand.Rand) (*Fake, counter.GoRoutineCounter)

NewFake constructs a new fake event clock. The given `r *rand.Rand` must henceforth not be used for any other purpose. If `r` is nil then a fresh one will be constructed, seeded with the current real time. The clientWG can be `nil` and if not is used to let Run know about additional work that has to complete before time can advance.

func (*Fake) EventAfterDuration

func (fec *Fake) EventAfterDuration(f eventclock.EventFunc, d time.Duration)

EventAfterDuration schedules the given function to be invoked once the given duration has passed.

func (*Fake) EventAfterTime

func (fec *Fake) EventAfterTime(f eventclock.EventFunc, t time.Time)

EventAfterTime schedules the given function to be invoked once the given time has arrived.

func (*Fake) GetNextTime

func (fec *Fake) GetNextTime() (time.Time, bool)

GetNextTime returns the next time at which there is work scheduled, and a bool indicating whether there is any such time

func (*Fake) Run

func (fec *Fake) Run(limit *time.Time)

Run runs all the events scheduled, and all the events they schedule, and so on, until there are none scheduled or the limit is not nil and the next time would exceed the limit. The associated GoRoutineCounter gates the advancing of time. That is, time is not advanced until all the associated work is finished.

func (*Fake) SetTime

func (fec *Fake) SetTime(t time.Time)

SetTime sets the time and runs to completion all events that should be started by the given time --- including any further events they schedule

func (*Fake) Sleep

func (fec *Fake) Sleep(duration time.Duration)

Sleep returns after the given duration has passed. Sleep must only be invoked in a goroutine that is counted in the Fake's associated GoRoutineCounter. Unlike the base FakeClock's Sleep, this method does not itself advance the clock but rather leaves that up to other actors (e.g., Run).

Jump to

Keyboard shortcuts

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