go-ethereum: github.com/axiomzen/go-ethereum/common/mclock Index | Files

package mclock

import "github.com/axiomzen/go-ethereum/common/mclock"

Package mclock is a wrapper for a monotonic clock source

Index

Package Files

mclock.go simclock.go

type AbsTime Uses

type AbsTime time.Duration

AbsTime represents absolute monotonic time.

func Now Uses

func Now() AbsTime

Now returns the current absolute monotonic time.

func (AbsTime) Add Uses

func (t AbsTime) Add(d time.Duration) AbsTime

Add returns t + d.

type Clock Uses

type Clock interface {
    Now() AbsTime
    Sleep(time.Duration)
    After(time.Duration) <-chan time.Time
}

Clock interface makes it possible to replace the monotonic system clock with a simulated clock.

type Simulated Uses

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

Simulated implements a virtual Clock for reproducible time-sensitive tests. It simulates a scheduler on a virtual timescale where actual processing takes zero time.

The virtual clock doesn't advance on its own, call Run to advance it and execute timers. Since there is no way to influence the Go scheduler, testing timeout behaviour involving goroutines needs special care. A good way to test such timeouts is as follows: First perform the action that is supposed to time out. Ensure that the timer you want to test is created. Then run the clock until after the timeout. Finally observe the effect of the timeout using a channel or semaphore.

func (*Simulated) ActiveTimers Uses

func (s *Simulated) ActiveTimers() int

func (*Simulated) After Uses

func (s *Simulated) After(d time.Duration) <-chan time.Time

After implements Clock.

func (*Simulated) Now Uses

func (s *Simulated) Now() AbsTime

Now implements Clock.

func (*Simulated) Run Uses

func (s *Simulated) Run(d time.Duration)

Run moves the clock by the given duration, executing all timers before that duration.

func (*Simulated) Sleep Uses

func (s *Simulated) Sleep(d time.Duration)

Sleep implements Clock.

func (*Simulated) WaitForTimers Uses

func (s *Simulated) WaitForTimers(n int)

type System Uses

type System struct{}

System implements Clock using the system clock.

func (System) After Uses

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

After implements Clock.

func (System) Now Uses

func (System) Now() AbsTime

Now implements Clock.

func (System) Sleep Uses

func (System) Sleep(d time.Duration)

Sleep implements Clock.

Package mclock imports 3 packages (graph). Updated 2019-07-06. Refresh now. Tools for package owners.