timeprovider

package
v2.2.1 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2025 License: Apache-2.0 Imports: 2 Imported by: 4

Documentation

Overview

*

  • Copyright (C) Couchbase, Inc 2025 - All Rights Reserved
  • Unauthorized copying of this file, via any medium is strictly prohibited
  • Proprietary and confidential

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CurrentTimeProvider

type CurrentTimeProvider struct{}

func (CurrentTimeProvider) Now

func (tp CurrentTimeProvider) Now() time.Time

func (CurrentTimeProvider) Ticker added in v2.2.0

func (tp CurrentTimeProvider) Ticker() Ticker

type FakeTicker added in v2.2.0

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

FakeTicker is a fake implementation of the 'Ticker' interface that can be used in tests. Whenever we want to run an interaction 'ForceTick' or 'TickIfElapsed' can be called.

func NewFakeTicker added in v2.2.0

func NewFakeTicker(provider TimeProvider) *FakeTicker

func (*FakeTicker) Channel added in v2.2.0

func (f *FakeTicker) Channel() <-chan time.Time

func (*FakeTicker) ForceTick added in v2.2.0

func (f *FakeTicker) ForceTick()

ForceTick sends the current time to the channel.

func (*FakeTicker) Start added in v2.2.0

func (f *FakeTicker) Start(dur time.Duration)

Start begins the ticker. As this is a fake, we just record 'dur' and the current time, allowing us to check whether we have elapsed.

func (*FakeTicker) Stop added in v2.2.0

func (f *FakeTicker) Stop()

func (*FakeTicker) TickIfElapsed added in v2.2.0

func (f *FakeTicker) TickIfElapsed()

TickIfElapsed sends the current time to the channel if the timer has elapsed.

type FakeTimeProvider added in v2.2.0

type FakeTimeProvider struct {
	Time    time.Time
	Tickers []*FakeTicker
}

FakeTimeProvider implements 'TimeProvider' and allows the time to be advanced. When this happens and a ticker has elapsed it is ticked.

func NewFakeTimeProvider added in v2.2.0

func NewFakeTimeProvider(start time.Time) *FakeTimeProvider

func (*FakeTimeProvider) AdvanceTimeBy added in v2.2.0

func (f *FakeTimeProvider) AdvanceTimeBy(d time.Duration)

AdvanceTimeBy advances the time by 'd', ticking any tickers that have elapsed.

func (*FakeTimeProvider) AdvanceTimeTo added in v2.2.0

func (f *FakeTimeProvider) AdvanceTimeTo(t time.Time)

AdvanceTimeTo sets the time to 't', ticking any tickers that have elapsed.

func (*FakeTimeProvider) Now added in v2.2.0

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

func (*FakeTimeProvider) Ticker added in v2.2.0

func (f *FakeTimeProvider) Ticker() Ticker

type MockTicker added in v2.2.1

type MockTicker struct {
	mock.Mock
}

MockTicker is an autogenerated mock type for the Ticker type

func NewMockTicker added in v2.2.1

func NewMockTicker(t interface {
	mock.TestingT
	Cleanup(func())
},
) *MockTicker

NewMockTicker creates a new instance of MockTicker. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.

func (*MockTicker) Channel added in v2.2.1

func (_m *MockTicker) Channel() <-chan time.Time

Channel provides a mock function with no fields

func (*MockTicker) Start added in v2.2.1

func (_m *MockTicker) Start(duration time.Duration)

Start provides a mock function with given fields: duration

func (*MockTicker) Stop added in v2.2.1

func (_m *MockTicker) Stop()

Stop provides a mock function with no fields

type MockTimeProvider

type MockTimeProvider struct {
	mock.Mock
}

MockTimeProvider is an autogenerated mock type for the TimeProvider type

func NewMockTimeProvider

func NewMockTimeProvider(t interface {
	mock.TestingT
	Cleanup(func())
},
) *MockTimeProvider

NewMockTimeProvider creates a new instance of MockTimeProvider. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.

func (*MockTimeProvider) Now

func (_m *MockTimeProvider) Now() time.Time

Now provides a mock function with no fields

func (*MockTimeProvider) Ticker added in v2.2.1

func (_m *MockTimeProvider) Ticker() Ticker

Ticker provides a mock function with no fields

type RealTicker added in v2.2.0

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

RealTicker is a wrapper around 'time.Ticker' that implements the 'Ticker' interface.

func NewRealTicker added in v2.2.0

func NewRealTicker() *RealTicker

func (*RealTicker) Channel added in v2.2.0

func (r *RealTicker) Channel() <-chan time.Time

func (*RealTicker) Start added in v2.2.0

func (r *RealTicker) Start(duration time.Duration)

func (*RealTicker) Stop added in v2.2.0

func (r *RealTicker) Stop()

type Ticker added in v2.2.0

type Ticker interface {
	Start(duration time.Duration)
	Channel() <-chan time.Time
	Stop()
}

Ticker is an interface for a timer that can be started, stopped, and queried for ticks, like 'time.Ticker'. We define this interface so that we can use a fake ticker in tests.

type TimeProvider

type TimeProvider interface {
	Now() time.Time
	Ticker() Ticker
}

Jump to

Keyboard shortcuts

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