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

Function TestIdleService

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

Source from the content-addressed store, hash-verified

11)
12
13func TestIdleService(t *testing.T) {
14 t.Parallel()
15
16 started := false
17 stopped := false
18
19 s := NewIdleService(func(ctx context.Context) error {
20 started = true
21 return nil
22 }, func(_ error) error {
23 stopped = true
24 return nil
25 })
26 defer s.StopAsync()
27
28 require.False(t, started)
29 require.Equal(t, New, s.State())
30 require.NoError(t, s.StartAsync(context.Background()))
31 require.Error(t, s.StartAsync(context.Background())) // cannot start twice
32 require.NoError(t, s.AwaitRunning(context.Background()))
33 require.True(t, started)
34 require.False(t, stopped)
35 require.Equal(t, Running, s.State())
36 s.StopAsync()
37 require.NoError(t, s.AwaitTerminated(context.Background()))
38 require.True(t, stopped)
39}
40
41func TestTimerService(t *testing.T) {
42 t.Parallel()

Callers

nothing calls this directly

Calls 8

NewIdleServiceFunction · 0.85
StopAsyncMethod · 0.65
EqualMethod · 0.65
StateMethod · 0.65
StartAsyncMethod · 0.65
AwaitRunningMethod · 0.65
AwaitTerminatedMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected