MCPcopy
hub / github.com/ContainerSSH/ContainerSSH / TestOneServiceCrash

Function TestOneServiceCrash

service/pool_test.go:76–124  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

74}
75
76func TestOneServiceCrash(t *testing.T) {
77 testLock := &sync.Mutex{}
78 pool := service.NewPool(service.NewLifecycleFactory(), log.NewTestLogger(t))
79 poolLifecycle := service.NewLifecycle(pool)
80 poolStarted := make(chan bool)
81 poolStopped := make(chan bool)
82 var poolStates []service.State
83 var serviceStates []service.State
84 poolLifecycle.OnRunning(func(s service.Service, l service.Lifecycle) {
85 poolStarted <- true
86 })
87 poolLifecycle.OnStateChange(func(s service.Service, l service.Lifecycle, state service.State) {
88 testLock.Lock()
89 defer testLock.Unlock()
90 poolStates = append(poolStates, state)
91 })
92
93 s := newTestService("Test service")
94 pool.Add(s).OnStateChange(func(s service.Service, l service.Lifecycle, state service.State) {
95 testLock.Lock()
96 defer testLock.Unlock()
97 serviceStates = append(serviceStates, state)
98 })
99
100 go func() {
101 err := poolLifecycle.Run()
102 if err == nil {
103 t.Fail()
104 }
105 poolStopped <- true
106 }()
107
108 <-poolStarted
109 s.Crash()
110 err := poolLifecycle.Wait()
111 testLock.Lock()
112 assert.NotNil(t, err)
113 assert.Equal(t, []service.State{
114 service.StateStarting,
115 service.StateRunning,
116 service.StateCrashed,
117 }, serviceStates)
118 assert.Equal(t, []service.State{
119 service.StateStarting,
120 service.StateRunning,
121 service.StateCrashed,
122 }, poolStates)
123 testLock.Unlock()
124}
125
126func TestOneServiceStartupCrash(t *testing.T) {
127 testLock := &sync.Mutex{}

Callers

nothing calls this directly

Calls 12

OnRunningMethod · 0.95
OnStateChangeMethod · 0.95
AddMethod · 0.95
RunMethod · 0.95
WaitMethod · 0.95
NewPoolFunction · 0.92
NewLifecycleFactoryFunction · 0.92
NewTestLoggerFunction · 0.92
NewLifecycleFunction · 0.92
newTestServiceFunction · 0.85
FailMethod · 0.80
CrashMethod · 0.80

Tested by

no test coverage detected