(t *testing.T)
| 74 | } |
| 75 | |
| 76 | func 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 | |
| 126 | func TestOneServiceStartupCrash(t *testing.T) { |
| 127 | testLock := &sync.Mutex{} |
nothing calls this directly
no test coverage detected