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

Function TestBasicManagerTransitions

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

Source from the content-addressed store, hash-verified

16}
17
18func TestBasicManagerTransitions(t *testing.T) {
19 t.Parallel()
20
21 s1 := serviceThatDoesntDoAnything()
22 s2 := serviceThatDoesntDoAnything()
23 s3 := serviceThatDoesntDoAnything()
24 gl := newGatheringManagerListener(t)
25
26 m, err := NewManager(s1, s2, s3)
27 require.NoError(t, err)
28 m.AddListener(gl)
29
30 states := m.ServicesByState()
31 for s, ss := range states {
32 require.Equal(t, New, s)
33 require.Len(t, ss, 3)
34 }
35
36 require.False(t, m.IsHealthy())
37 require.False(t, m.IsStopped())
38 require.NoError(t, m.StartAsync(context.Background()))
39 require.NoError(t, m.AwaitHealthy(context.Background()))
40 require.True(t, m.IsHealthy())
41 require.False(t, m.IsStopped())
42
43 states = m.ServicesByState()
44 for s, ss := range states {
45 require.Equal(t, Running, s)
46 require.Len(t, ss, 3)
47 }
48
49 m.StopAsync()
50 require.NoError(t, m.AwaitStopped(context.Background()))
51 require.False(t, m.IsHealthy())
52 require.True(t, m.IsStopped())
53
54 states = m.ServicesByState()
55 for s, ss := range states {
56 require.Equal(t, Terminated, s)
57 require.Len(t, ss, 3)
58 }
59
60 require.NoError(t, gl.AwaitTerminated(context.Background()))
61 require.Equal(t, []string{"healthy", "stopped"}, gl.log)
62}
63
64func TestManagerRequiresServicesToBeInNewState(t *testing.T) {
65 t.Parallel()

Callers

nothing calls this directly

Calls 14

AddListenerMethod · 0.95
ServicesByStateMethod · 0.95
IsHealthyMethod · 0.95
IsStoppedMethod · 0.95
StartAsyncMethod · 0.95
AwaitHealthyMethod · 0.95
StopAsyncMethod · 0.95
AwaitStoppedMethod · 0.95
NewManagerFunction · 0.70
AwaitTerminatedMethod · 0.65

Tested by

no test coverage detected