(t *testing.T)
| 49 | } |
| 50 | |
| 51 | func TestCrash(t *testing.T) { |
| 52 | s := newTestService("Test service") |
| 53 | l := service.NewLifecycle(s) |
| 54 | starting := make(chan bool) |
| 55 | running := make(chan bool) |
| 56 | crashed := make(chan bool, 1) |
| 57 | l.OnStarting(func(s service.Service, l service.Lifecycle) { |
| 58 | starting <- true |
| 59 | }) |
| 60 | l.OnRunning(func(s service.Service, l service.Lifecycle) { |
| 61 | running <- true |
| 62 | }) |
| 63 | l.OnCrashed(func(s service.Service, l service.Lifecycle, err error) { |
| 64 | crashed <- true |
| 65 | }) |
| 66 | l.OnStopped(func(s service.Service, l service.Lifecycle) { |
| 67 | t.Fail() |
| 68 | }) |
| 69 | l.OnStopping(func(s service.Service, l service.Lifecycle, shutdownContext context.Context) { |
| 70 | t.Fail() |
| 71 | }) |
| 72 | go func() { |
| 73 | if err := l.Run(); err == nil { |
| 74 | assert.Fail(t, "service did not crash") |
| 75 | } |
| 76 | }() |
| 77 | <-starting |
| 78 | <-running |
| 79 | s.Crash() |
| 80 | <-crashed |
| 81 | } |
nothing calls this directly
no test coverage detected