MCPcopy
hub / github.com/ContainerSSH/ContainerSSH / TestOneServiceStartupCrash

Function TestOneServiceStartupCrash

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

Source from the content-addressed store, hash-verified

124}
125
126func TestOneServiceStartupCrash(t *testing.T) {
127 testLock := &sync.Mutex{}
128 pool := service.NewPool(service.NewLifecycleFactory(), log.NewTestLogger(t))
129 poolLifecycle := service.NewLifecycle(pool)
130 var poolStates []service.State
131 var serviceStates []service.State
132 startup := make(chan struct{})
133 poolLifecycle.OnStarting(func(s service.Service, l service.Lifecycle) {
134 startup <- struct{}{}
135 })
136 poolLifecycle.OnStateChange(func(s service.Service, l service.Lifecycle, state service.State) {
137 poolStates = append(poolStates, state)
138 })
139
140 s := newTestService("Test service")
141 s.CrashStartup()
142 pool.Add(s).OnStateChange(func(s service.Service, l service.Lifecycle, state service.State) {
143 testLock.Lock()
144 defer testLock.Unlock()
145 serviceStates = append(serviceStates, state)
146 })
147
148 go func() {
149 err := poolLifecycle.Run()
150 if err == nil {
151 t.Fail()
152 }
153 }()
154
155 <-startup
156 err := poolLifecycle.Wait()
157 testLock.Lock()
158 assert.NotNil(t, err)
159 assert.Equal(t, []service.State{
160 service.StateStarting,
161 service.StateCrashed,
162 }, serviceStates)
163 assert.Equal(t, []service.State{
164 service.StateStarting,
165 service.StateStopping,
166 service.StateCrashed,
167 }, poolStates)
168 testLock.Unlock()
169}
170
171func TestTwoServices(t *testing.T) {
172 testLock := &sync.Mutex{}

Callers

nothing calls this directly

Calls 12

OnStartingMethod · 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
CrashStartupMethod · 0.80
FailMethod · 0.80

Tested by

no test coverage detected