(t *testing.T)
| 31 | } |
| 32 | |
| 33 | func TestOneService(t *testing.T) { |
| 34 | pool := service.NewPool(service.NewLifecycleFactory(), log.NewTestLogger(t)) |
| 35 | poolLifecycle := service.NewLifecycle(pool) |
| 36 | poolStarted := make(chan bool) |
| 37 | poolStopped := make(chan bool) |
| 38 | var poolStates []service.State |
| 39 | var serviceStates []service.State |
| 40 | poolLifecycle.OnRunning(func(s service.Service, l service.Lifecycle) { |
| 41 | poolStarted <- true |
| 42 | }) |
| 43 | poolLifecycle.OnStateChange(func(s service.Service, l service.Lifecycle, state service.State) { |
| 44 | poolStates = append(poolStates, state) |
| 45 | }) |
| 46 | |
| 47 | s := newTestService("Test service") |
| 48 | pool.Add(s).OnStateChange(func(s service.Service, l service.Lifecycle, state service.State) { |
| 49 | serviceStates = append(serviceStates, state) |
| 50 | }) |
| 51 | |
| 52 | go func() { |
| 53 | err := poolLifecycle.Run() |
| 54 | if err != nil { |
| 55 | t.Fail() |
| 56 | } |
| 57 | poolStopped <- true |
| 58 | }() |
| 59 | |
| 60 | <-poolStarted |
| 61 | poolLifecycle.Stop(context.Background()) |
| 62 | assert.Equal(t, []service.State{ |
| 63 | service.StateStarting, |
| 64 | service.StateRunning, |
| 65 | service.StateStopping, |
| 66 | service.StateStopped, |
| 67 | }, serviceStates) |
| 68 | assert.Equal(t, []service.State{ |
| 69 | service.StateStarting, |
| 70 | service.StateRunning, |
| 71 | service.StateStopping, |
| 72 | service.StateStopped, |
| 73 | }, poolStates) |
| 74 | } |
| 75 | |
| 76 | func TestOneServiceCrash(t *testing.T) { |
| 77 | testLock := &sync.Mutex{} |
nothing calls this directly
no test coverage detected