Documentation ¶
Index ¶
- type MockClock
- type MockEndpoint
- func (ep *MockEndpoint) BuildReport(report metrics.StampedMetricReport) (pipeline.EndpointReport, error)
- func (wfc *MockEndpoint) Calls() int32
- func (wfc *MockEndpoint) DoAndWait(t *testing.T, calls int32, f func())
- func (ep *MockEndpoint) IsTransient(err error) bool
- func (ep *MockEndpoint) Name() string
- func (ep *MockEndpoint) Release() error
- func (ep *MockEndpoint) Reports() (reports []pipeline.EndpointReport)
- func (ep *MockEndpoint) Send(report pipeline.EndpointReport) error
- func (ep *MockEndpoint) SetBuildErr(err error)
- func (ep *MockEndpoint) SetSendErr(err error)
- func (ep *MockEndpoint) Use()
- type MockInput
- func (i *MockInput) AddReport(report metrics.MetricReport) error
- func (wfc *MockInput) Calls() int32
- func (wfc *MockInput) DoAndWait(t *testing.T, calls int32, f func())
- func (i *MockInput) Release() error
- func (i *MockInput) Reports() (reports []metrics.MetricReport)
- func (i *MockInput) SetAddError(err error)
- func (i *MockInput) Use()
- type MockSender
- func (wfc *MockSender) Calls() int32
- func (wfc *MockSender) DoAndWait(t *testing.T, calls int32, f func())
- func (s *MockSender) Endpoints() []string
- func (s *MockSender) Release() error
- func (s *MockSender) Reports() (reports []metrics.MetricReport)
- func (s *MockSender) Send(report metrics.StampedMetricReport) error
- func (s *MockSender) SetSendError(err error)
- func (s *MockSender) Use()
- type MockStatsRecorder
- func (wfc *MockStatsRecorder) Calls() int32
- func (wfc *MockStatsRecorder) DoAndWait(t *testing.T, calls int32, f func())
- func (sr *MockStatsRecorder) Failed() []RecordedEntry
- func (sr *MockStatsRecorder) Register(id string, handlers []string)
- func (sr *MockStatsRecorder) Registered() map[string][]string
- func (sr *MockStatsRecorder) SendFailed(id string, handler string)
- func (sr *MockStatsRecorder) SendSucceeded(id string, handler string)
- func (sr *MockStatsRecorder) Succeeded() []RecordedEntry
- type RecordedEntry
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MockClock ¶
type MockClock interface { clock.Clock SetNow(time.Time) // GetNextFireTime returns the time that the next Timer will fire, or the zero value if no timers // are set. GetNextFireTime() time.Time }
MockClock is an extension of Clock that adds the ability to set the current time. Now returns the value passed to SetNow until a new value is set.
Timers created by a MockClock will fire once the clock's time is set to or after the calculated fire time. This helps enable deterministic tests involving timers. However, because a MockClock's time doesn't continuously increase, a couple of considerations should be followed to avoid racy conditions in tests.
Avoid calls to Clock.Now() outside of the test thread. For example, when creating timers asynchronously, avoid calls to clock.Now() and instead get the base time from the test thread. e.g.,
func NewComponent(c clock.Clock) *Component { c = &Component{clock: c} go c.run(c.Now()) // Retrieve the initial time from this thread. }
func (c *Component) run(now time.Time) { fireAt := now.Add(someDelay) for { tmr := c.clock.NewTimerAt(fireAt) select { case <-c.someChan: c.handleEvent()
case n := <-tmr.GetC(): c.somePeriodicOperation() // Compute next fire time based on value received from timer. fireAt = n.Add(someDelay) } tmr.Cancel() }
When creating a new timer, use Clock.NewTimerAt(time.Time) to specify a point in time at which the timer should fire, and calculate that time based on a known base time (#1). Using Clock.NewTimer(time.Duration) can lead to race conditions in tests:
d := someDelay - c.clock.Now().Sub(c.lastFireTime) // <-- if the MockClock's time is advanced here, the new timer may not fire when expected. tmr := c.clock.NewTimer(d)
Instead:
now := c.clock.Now() nextFire := now.Add(someDelay - now.Sub(c.lastFireTime)) tmr := c.clock.NewTimerAt(nextFire)
func NewMockClock ¶
func NewMockClock() MockClock
NewMockClock creates a new MockClock instance that initially returns time zero.
type MockEndpoint ¶
Type MockEndpoint is a mock endpoint.Endpoint.
func NewMockEndpoint ¶
func NewMockEndpoint(name string) *MockEndpoint
NewMockEndpoint creates a new MockEndpoint with the given name.
func (*MockEndpoint) BuildReport ¶
func (ep *MockEndpoint) BuildReport(report metrics.StampedMetricReport) (pipeline.EndpointReport, error)
func (*MockEndpoint) DoAndWait ¶
DoAndWait executes the given function and then waits until the total number of calls reaches the given value.
func (*MockEndpoint) IsTransient ¶
func (ep *MockEndpoint) IsTransient(err error) bool
func (*MockEndpoint) Name ¶
func (ep *MockEndpoint) Name() string
func (*MockEndpoint) Release ¶
func (ep *MockEndpoint) Release() error
func (*MockEndpoint) Reports ¶
func (ep *MockEndpoint) Reports() (reports []pipeline.EndpointReport)
func (*MockEndpoint) Send ¶
func (ep *MockEndpoint) Send(report pipeline.EndpointReport) error
func (*MockEndpoint) SetBuildErr ¶
func (ep *MockEndpoint) SetBuildErr(err error)
func (*MockEndpoint) SetSendErr ¶
func (ep *MockEndpoint) SetSendErr(err error)
func (*MockEndpoint) Use ¶
func (ep *MockEndpoint) Use()
type MockInput ¶
Type MockInput is a mock pipeline.Input.
func (*MockInput) DoAndWait ¶
DoAndWait executes the given function and then waits until the total number of calls reaches the given value.
func (*MockInput) Reports ¶
func (i *MockInput) Reports() (reports []metrics.MetricReport)
func (*MockInput) SetAddError ¶
type MockSender ¶
Type MockSender is a mock sender.Sender.
func NewMockSender ¶
func NewMockSender(endpoints ...string) *MockSender
NewMockSender creates a new MockSender with the given endpoint IDs.
func (*MockSender) DoAndWait ¶
DoAndWait executes the given function and then waits until the total number of calls reaches the given value.
func (*MockSender) Endpoints ¶
func (s *MockSender) Endpoints() []string
func (*MockSender) Release ¶
func (s *MockSender) Release() error
func (*MockSender) Reports ¶
func (s *MockSender) Reports() (reports []metrics.MetricReport)
func (*MockSender) Send ¶
func (s *MockSender) Send(report metrics.StampedMetricReport) error
func (*MockSender) SetSendError ¶
func (s *MockSender) SetSendError(err error)
func (*MockSender) Use ¶
func (s *MockSender) Use()
type MockStatsRecorder ¶
type MockStatsRecorder struct {
// contains filtered or unexported fields
}
Type MockStatsRecorder is a mock stats.StatsRecorder.
func NewMockStatsRecorder ¶
func NewMockStatsRecorder() *MockStatsRecorder
func (*MockStatsRecorder) DoAndWait ¶
DoAndWait executes the given function and then waits until the total number of calls reaches the given value.
func (*MockStatsRecorder) Failed ¶
func (sr *MockStatsRecorder) Failed() []RecordedEntry
func (*MockStatsRecorder) Register ¶
func (sr *MockStatsRecorder) Register(id string, handlers []string)
func (*MockStatsRecorder) Registered ¶
func (sr *MockStatsRecorder) Registered() map[string][]string
func (*MockStatsRecorder) SendFailed ¶
func (sr *MockStatsRecorder) SendFailed(id string, handler string)
func (*MockStatsRecorder) SendSucceeded ¶
func (sr *MockStatsRecorder) SendSucceeded(id string, handler string)
func (*MockStatsRecorder) Succeeded ¶
func (sr *MockStatsRecorder) Succeeded() []RecordedEntry