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

Function TestBasicManagerTransitions

pkg/util/services/manager_test.go:17–61  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

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

Tested by

no test coverage detected