(t *testing.T)
| 230 | } |
| 231 | |
| 232 | func TestManagerAwaitWithContextCancellation(t *testing.T) { |
| 233 | t.Parallel() |
| 234 | |
| 235 | s1 := serviceThatStopsOnItsOwnAfterTimeout(200 * time.Millisecond) |
| 236 | s2 := serviceThatStopsOnItsOwnAfterTimeout(300 * time.Millisecond) |
| 237 | gl := newGatheringManagerListener(t) |
| 238 | |
| 239 | m, err := NewManager(s1, s2) |
| 240 | require.NoError(t, err) |
| 241 | m.AddListener(gl) |
| 242 | |
| 243 | // test context cancellation |
| 244 | stoppedContext, cancel := context.WithCancel(context.Background()) |
| 245 | cancel() |
| 246 | |
| 247 | require.Equal(t, context.Canceled, m.AwaitHealthy(stoppedContext)) // since no services have started yet, and context is stopped, must return error quickly |
| 248 | |
| 249 | // start all services |
| 250 | require.NoError(t, m.StartAsync(context.Background())) |
| 251 | |
| 252 | shortContext, cancel := context.WithTimeout(context.Background(), 10*time.Millisecond) |
| 253 | defer cancel() |
| 254 | |
| 255 | require.Equal(t, context.DeadlineExceeded, m.AwaitStopped(shortContext)) |
| 256 | require.NoError(t, m.AwaitStopped(context.Background())) |
| 257 | |
| 258 | require.NoError(t, gl.AwaitTerminated(context.Background())) |
| 259 | require.Equal(t, []string{"healthy", "stopped"}, gl.log) |
| 260 | } |
| 261 | |
| 262 | func mergeStates(m map[State][]Service, states ...State) []Service { |
| 263 | result := []Service(nil) |
nothing calls this directly
no test coverage detected