MCPcopy Create free account
hub / github.com/cortexproject/cortex / runRandomTest

Method runRandomTest

pkg/testexporter/correctness/runner.go:176–219  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

174}
175
176func (r *Runner) runRandomTest() {
177 r.mtx.Lock()
178 tc := r.cases[rand.Intn(len(r.cases))]
179 r.mtx.Unlock()
180
181 ctx := context.Background()
182 log, ctx := spanlogger.New(ctx, "runRandomTest")
183 span, trace := opentracing.SpanFromContext(ctx), "<none>"
184 if span != nil {
185 trace = fmt.Sprintf("%s", span.Context())
186 }
187
188 minQueryTime := tc.MinQueryTime()
189 level.Info(log).Log("name", tc.Name(), "trace", trace, "minTime", minQueryTime)
190 defer log.Finish()
191
192 // pick a random time to start testStart and now
193 // pick a random length between minDuration and maxDuration
194 now := time.Now()
195 start := minQueryTime.Add(time.Duration(rand.Int63n(int64(now.Sub(minQueryTime)))))
196 duration := r.cfg.testQueryMinSize +
197 time.Duration(rand.Int63n(int64(r.cfg.testQueryMaxSize)-int64(r.cfg.testQueryMinSize)))
198 if start.Add(-duration).Before(minQueryTime) {
199 duration = start.Sub(minQueryTime)
200 }
201 if duration < r.cfg.testQueryMinSize {
202 return
203 }
204
205 // round off duration to minutes because we anyways have a window in minutes while doing queries.
206 duration = (duration / time.Minute) * time.Minute
207 level.Info(log).Log("start", start, "duration", duration)
208
209 passed, err := tc.Test(ctx, r.client, r.cfg.ExtraSelectors, start, duration)
210 if err != nil {
211 level.Error(log).Log("err", err)
212 }
213
214 if passed {
215 testcaseResult.WithLabelValues(tc.Name(), success).Inc()
216 } else {
217 testcaseResult.WithLabelValues(tc.Name(), fail).Inc()
218 }
219}

Callers 1

verifyLoopMethod · 0.95

Calls 11

NewFunction · 0.92
FinishMethod · 0.80
BeforeMethod · 0.80
MinQueryTimeMethod · 0.65
NameMethod · 0.65
TestMethod · 0.65
ContextMethod · 0.45
LogMethod · 0.45
AddMethod · 0.45
ErrorMethod · 0.45
IncMethod · 0.45

Tested by

no test coverage detected