package timeutil

import "github.com/ydb-platform/ydb-go-sdk/v3/testutil/timeutil"

Index

Functions

func Now

func Now() time.Time

Now returns result of time.Now() if no TestHookTimeNow set up.

func StubTestHookNewTimer

func StubTestHookNewTimer(f func(time.Duration) Timer) (cleanup func())

StubTestHookNewTimer stubs all creation of Timers for ydb packages. It returns cleanup function that MUST be called after test execution.

NOTE: tests using this function MUST not be called concurrently.

func StubTestHookTimeNow

func StubTestHookTimeNow(now time.Time) (shifter func(time.Duration), cleanup func())

StubTestHookTimeNow stubs all `Now()` use for ydb packages.

It sets up current time to given now time. It returns time shifter function that shifts current time by given duration. It returns cleanup function that MUST be called after test execution.

NOTE: tests using this function MUST not be called concurrently.

func Until

func Until(t time.Time) time.Duration

Until returns the duration until t. It is shorthand for t.Sub(timeutil.Now()).

Types

type Timer

type Timer interface {
	Reset(time.Duration) bool
	Stop() bool
	C() <-chan time.Time
}

Timer is the interface used by node watcher to be periodically triggered to prepare some action.

func AfterFunc

func AfterFunc(d time.Duration, f func()) Timer

AfterFunc waits for the duration to elapse and then calls f in its own goroutine. It returns a Timer that can be used to cancel the call using its Stop method.

func NewStoppedTimer

func NewStoppedTimer() Timer

NewStoppedTimer creates a new stopped Timer.

func NewTimer

func NewTimer(d time.Duration) Timer

NewTimer creates a new Timer that will send the current time on its channel after at least duration d.

It uses time package as timer implementation.

Source Files

hook.go timeutil.go

Directories

PathSynopsis
testutil/timeutil/timetest
Version
v3.34.0
Published
Aug 16, 2022
Platform
darwin/amd64
Imports
3 packages
Last checked
3 seconds ago

Tools for package owners.