Documentation ¶
Overview ¶
Package testutil provides easy ways to generate some random or deterministic data that can be use for tests or benchmarks.
All the publicly shared trace agent model is available.
It avoids the cumbersome step of having to redefine complicated structs in every test case and maintain common methods for quick access to almost all kind of stub data needed. It should NEVER be imported in a program, most likely in one-off projects or fuzz modes or test suites.
Index ¶
- Variables
- func GetTestSpan() *pb.Span
- func GetTestTrace(traceN, size int, realisticIDs bool) pb.Traces
- func RandomServices(maxServices, maxTags int) pb.ServicesMetadata
- func RandomSizedBytes(size int) []byte
- func RandomSpan() *pb.Span
- func RandomSpanDuration() int64
- func RandomSpanError() int32
- func RandomSpanID() uint64
- func RandomSpanMeta() map[string]string
- func RandomSpanMetrics() map[string]float64
- func RandomSpanName() string
- func RandomSpanParentID() uint64
- func RandomSpanResource() string
- func RandomSpanService() string
- func RandomSpanStart() int64
- func RandomSpanTraceID() uint64
- func RandomSpanType() string
- func RandomStatsBucket(n int) agent.StatsBucket
- func RandomStringMap() map[string]string
- func RandomTrace(maxLevels, maxSpans int) pb.Trace
- func RandomWeightedSpan() *agent.WeightedSpan
- func StatsBucketWithSpans(spans []*agent.WeightedSpan) agent.StatsBucket
- func TestDistribution() agent.Distribution
- func TestSpan() *pb.Span
- func TestStatsBucket() agent.StatsBucket
- func TestWeightedSpan() *agent.WeightedSpan
- type CountSummary
- type GaugeSummary
- type MockEngine
- type StatsClientCountArgs
- type StatsClientGaugeArgs
- type StatsClientHistogramArgs
- type TestBackoffTimer
- func (t *TestBackoffTimer) Close()
- func (t *TestBackoffTimer) CurrentDelay() time.Duration
- func (t *TestBackoffTimer) NumRetries() int
- func (t *TestBackoffTimer) ReceiveTick() <-chan time.Time
- func (t *TestBackoffTimer) Reset()
- func (t *TestBackoffTimer) ScheduleRetry(err error) (int, time.Duration)
- func (t *TestBackoffTimer) Stop()
- func (t *TestBackoffTimer) TriggerTick()
- type TestStatsClient
- func (c *TestStatsClient) Count(name string, value int64, tags []string, rate float64) error
- func (c *TestStatsClient) Gauge(name string, value float64, tags []string, rate float64) error
- func (c *TestStatsClient) GetCountSummaries() map[string]*CountSummary
- func (c *TestStatsClient) GetGaugeSummaries() map[string]*GaugeSummary
- func (c *TestStatsClient) Histogram(name string, value float64, tags []string, rate float64) error
- func (c *TestStatsClient) Reset()
Constants ¶
This section is empty.
Variables ¶
var TestDistroValues = []int64{}/* 1000 elements not displayed */
TestDistroValues is a pre-defined list of values
var YearNS = time.Duration(time.Hour * 24 * 365).Nanoseconds()
YearNS is the number of nanoseconds in a year
Functions ¶
func GetTestTrace ¶
GetTestTrace returns a []Trace that is composed by “traceN“ number of traces, each one composed by “size“ number of spans.
func RandomServices ¶
func RandomServices(maxServices, maxTags int) pb.ServicesMetadata
RandomServices generates random services metadata
func RandomSizedBytes ¶
RandomSizedBytes creates a random byte slice with the specified size.
func RandomSpan ¶
RandomSpan generates a wide-variety of spans, useful to test robustness & performance
func RandomSpanDuration ¶
func RandomSpanDuration() int64
RandomSpanDuration generates a random span duration
func RandomSpanError ¶
func RandomSpanError() int32
RandomSpanError generates a random span error code
func RandomSpanMeta ¶
RandomSpanMeta generates some random span metadata
func RandomSpanMetrics ¶
RandomSpanMetrics generates some random span metrics
func RandomSpanName ¶
func RandomSpanName() string
RandomSpanName generates a random span name string
func RandomSpanParentID ¶
func RandomSpanParentID() uint64
RandomSpanParentID generates a random span parent ID
func RandomSpanResource ¶
func RandomSpanResource() string
RandomSpanResource generates a random span resource string
func RandomSpanService ¶
func RandomSpanService() string
RandomSpanService generates a random span service string
func RandomSpanStart ¶
func RandomSpanStart() int64
RandomSpanStart generates a span start timestamp
func RandomSpanTraceID ¶
func RandomSpanTraceID() uint64
RandomSpanTraceID generates a random trace ID
func RandomStatsBucket ¶
func RandomStatsBucket(n int) agent.StatsBucket
RandomStatsBucket returns a bucket made from n random spans, useful to run benchmarks and tests
func RandomStringMap ¶
RandomStringMap creates a random map with string keys and values.
func RandomTrace ¶
RandomTrace generates a random trace with a depth from 1 to maxLevels of spans. Each level has at most maxSpans items.
func RandomWeightedSpan ¶
func RandomWeightedSpan() *agent.WeightedSpan
RandomWeightedSpan generates a random weighted span, useful for stats tests
func StatsBucketWithSpans ¶
func StatsBucketWithSpans(spans []*agent.WeightedSpan) agent.StatsBucket
StatsBucketWithSpans returns a stats bucket populated with spans stats
func TestDistribution ¶
func TestDistribution() agent.Distribution
TestDistribution returns a distribution with pre-defined values
func TestStatsBucket ¶
func TestStatsBucket() agent.StatsBucket
TestStatsBucket returns a fixed stats bucket to be used in unit tests
func TestWeightedSpan ¶
func TestWeightedSpan() *agent.WeightedSpan
TestWeightedSpan returns a static test weighted span for reproductive stats tests
Types ¶
type CountSummary ¶
type CountSummary struct { Calls []StatsClientCountArgs Sum int64 }
CountSummary contains a summary of all Count method calls to a particular StatsClient for a particular key.
type GaugeSummary ¶
type GaugeSummary struct { Calls []StatsClientGaugeArgs Last float64 Max float64 }
GaugeSummary contains a summary of all Gauge method calls to a particular StatsClient for a particular key.
type MockEngine ¶
type MockEngine struct {
// contains filtered or unexported fields
}
MockEngine mocks a sampler engine
func NewMockEngine ¶
func NewMockEngine(wantSampled bool, wantRate float64) *MockEngine
NewMockEngine returns a MockEngine for tests
func (*MockEngine) GetState ¶
func (e *MockEngine) GetState() interface{}
GetState mocks Engine.GetState()
func (*MockEngine) GetType ¶
func (e *MockEngine) GetType() sampler.EngineType
GetType mocks Engine.GetType()
type StatsClientCountArgs ¶
StatsClientCountArgs represents arguments to a StatsClient Count method call.
type StatsClientGaugeArgs ¶
StatsClientGaugeArgs represents arguments to a StatsClient Gauge method call.
type StatsClientHistogramArgs ¶
StatsClientHistogramArgs represents arguments to a StatsClient Histogram method call.
type TestBackoffTimer ¶
type TestBackoffTimer struct {
// contains filtered or unexported fields
}
TestBackoffTimer is a backoff timer that ticks on-demand.
func NewTestBackoffTimer ¶
func NewTestBackoffTimer() *TestBackoffTimer
NewTestBackoffTimer creates a new instance of a TestBackoffTimer.
func (*TestBackoffTimer) Close ¶
func (t *TestBackoffTimer) Close()
Close closes the ticking channel of this backoff timer.
func (*TestBackoffTimer) CurrentDelay ¶
func (t *TestBackoffTimer) CurrentDelay() time.Duration
CurrentDelay in a TestBackoffTimer always returns 0.
func (*TestBackoffTimer) NumRetries ¶
func (t *TestBackoffTimer) NumRetries() int
NumRetries in a TestBackoffTimer always returns 0.
func (*TestBackoffTimer) ReceiveTick ¶
func (t *TestBackoffTimer) ReceiveTick() <-chan time.Time
ReceiveTick returns the channel where ticks are sent.
func (*TestBackoffTimer) Reset ¶
func (t *TestBackoffTimer) Reset()
Reset in a TestBackoffTimer is a no-op.
func (*TestBackoffTimer) ScheduleRetry ¶
func (t *TestBackoffTimer) ScheduleRetry(err error) (int, time.Duration)
ScheduleRetry on a TestBackoffTimer is a no-op.
func (*TestBackoffTimer) Stop ¶
func (t *TestBackoffTimer) Stop()
Stop in a TestBackoffTimer is a no-op.
func (*TestBackoffTimer) TriggerTick ¶
func (t *TestBackoffTimer) TriggerTick()
TriggerTick immediately sends a tick with the current timestamp through the ticking channel.
type TestStatsClient ¶
type TestStatsClient struct { GaugeErr error GaugeCalls []StatsClientGaugeArgs CountErr error CountCalls []StatsClientCountArgs HistogramErr error HistogramCalls []StatsClientHistogramArgs // contains filtered or unexported fields }
TestStatsClient is a mocked StatsClient that records all calls and replies with configurable error return values.
func (*TestStatsClient) GetCountSummaries ¶
func (c *TestStatsClient) GetCountSummaries() map[string]*CountSummary
GetCountSummaries computes summaries for all names supplied as parameters to Count calls.
func (*TestStatsClient) GetGaugeSummaries ¶
func (c *TestStatsClient) GetGaugeSummaries() map[string]*GaugeSummary
GetGaugeSummaries computes summaries for all names supplied as parameters to Gauge calls.
func (*TestStatsClient) Histogram ¶
Histogram records a call to a Histogram operation and replies with HistogramErr
func (*TestStatsClient) Reset ¶
func (c *TestStatsClient) Reset()
Reset resets client's internal records.