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

Function TestTimerService

pkg/util/services/services_test.go:41–66  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

39}
40
41func TestTimerService(t *testing.T) {
42 t.Parallel()
43
44 var iterations atomic.Uint64
45
46 s := NewTimerService(100*time.Millisecond, nil, func(ctx context.Context) error {
47 iterations.Inc()
48 return nil
49 }, nil)
50 defer s.StopAsync()
51
52 require.Equal(t, New, s.State())
53 require.NoError(t, s.StartAsync(context.Background()))
54 require.Error(t, s.StartAsync(context.Background()))
55 require.NoError(t, s.AwaitRunning(context.Background()))
56 require.Equal(t, Running, s.State())
57
58 time.Sleep(1 * time.Second)
59
60 val := iterations.Load()
61 require.NotZero(t, val) // we should observe some iterations now
62
63 s.StopAsync()
64 require.NoError(t, s.AwaitTerminated(context.Background()))
65 require.Equal(t, Terminated, s.State())
66}
67
68func TestHelperFunctionsNoError(t *testing.T) {
69 t.Parallel()

Callers

nothing calls this directly

Calls 10

NewTimerServiceFunction · 0.85
LoadMethod · 0.80
StopAsyncMethod · 0.65
EqualMethod · 0.65
StateMethod · 0.65
StartAsyncMethod · 0.65
AwaitRunningMethod · 0.65
AwaitTerminatedMethod · 0.65
IncMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected