MCPcopy
hub / github.com/grafana/tempo / TestSimulateLatency

Function TestSimulateLatency

pkg/traceql/fake_data_test.go:122–153  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

120}
121
122func TestSimulateLatency(t *testing.T) {
123 synctest.Test(t, func(t *testing.T) {
124 for range 10000 {
125 start := time.Now()
126 simulateLatency(100*time.Second, 0)
127 elapsed := time.Since(start)
128
129 assert.InDelta(t, elapsed, 100*time.Second, float64(testAccuracy))
130 }
131 })
132
133 synctest.Test(t, func(t *testing.T) {
134 // With std dev, should be around 100s but can vary
135 total := 10000
136 var outOfRange int
137 duration := 100 * time.Second
138 stdDev := 10 * time.Second
139 for range total {
140 start := time.Now()
141 simulateLatency(duration, stdDev)
142 elapsed := time.Since(start)
143
144 if elapsed > duration+2*stdDev {
145 outOfRange++
146 }
147 assert.InDelta(t, duration, elapsed, float64(3*stdDev+testAccuracy), "should not be outside of 3 sigmas")
148 }
149 // According to 3SR, 5% possibility of having a number outside of 2 standart deviation of the mean.
150 // As the process is random, to reduce possibility of false positives, doubling the expected value.
151 assert.Less(t, float64(outOfRange)/float64(total), 0.1, "possibly wrong distribution")
152 })
153}

Callers

nothing calls this directly

Calls 4

simulateLatencyFunction · 0.85
TestMethod · 0.80
NowMethod · 0.65
LessMethod · 0.45

Tested by

no test coverage detected