(t *testing.T)
| 124 | } |
| 125 | |
| 126 | func 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 | |
| 171 | func TestTwoServices(t *testing.T) { |
| 172 | testLock := &sync.Mutex{} |
nothing calls this directly
no test coverage detected