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

Function Test_job

modules/generator/registry/job_test.go:13–48  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

11)
12
13func Test_job(t *testing.T) {
14 synctest.Test(t, func(t *testing.T) {
15 interval := durationPtr(200 * time.Millisecond)
16
17 ctx, cancel := context.WithCancel(context.Background())
18
19 var jobTimes []time.Duration
20 lastRun := time.Now()
21
22 go job(
23 ctx,
24 func(_ context.Context) {
25 diff := time.Since(lastRun)
26 lastRun = time.Now()
27
28 jobTimes = append(jobTimes, diff)
29 fmt.Println(diff)
30
31 *interval += 20 * time.Millisecond
32 },
33 func() time.Duration {
34 return *interval
35 },
36 )
37
38 time.Sleep(1 * time.Second)
39
40 cancel()
41
42 require.Len(t, jobTimes, 4)
43 require.InDelta(t, 200*time.Millisecond, jobTimes[0], float64(10*time.Millisecond))
44 require.InDelta(t, 220*time.Millisecond, jobTimes[1], float64(10*time.Millisecond))
45 require.InDelta(t, 240*time.Millisecond, jobTimes[2], float64(10*time.Millisecond))
46 require.InDelta(t, 260*time.Millisecond, jobTimes[3], float64(10*time.Millisecond))
47 })
48}
49
50func durationPtr(d time.Duration) *time.Duration {
51 return &d

Callers

nothing calls this directly

Calls 6

TestMethod · 0.80
durationPtrFunction · 0.70
jobFunction · 0.70
NowMethod · 0.65
SleepMethod · 0.65
LenMethod · 0.65

Tested by

no test coverage detected