MCPcopy
hub / github.com/grafana/dskit / TestIdleService

Function TestIdleService

services/services_test.go:18–44  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 8

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

Tested by

no test coverage detected