lib/api: Prevent leaks in tests (#6227)

This commit is contained in:
Simon Frei
2019-12-13 09:26:41 +01:00
committed by Jakob Borg
parent 8140350094
commit de64ffddab
2 changed files with 34 additions and 16 deletions

View File

@@ -361,7 +361,10 @@ func (s *service) serve(ctx context.Context) {
l.Infoln("Access the GUI via the following URL:", guiCfg.URL())
if s.started != nil {
// only set when run by the tests
s.started <- listener.Addr().String()
select {
case <-ctx.Done(): // Shouldn't return directly due to cleanup below
case s.started <- listener.Addr().String():
}
}
// Indicate successful initial startup, to ourselves and to interested
@@ -376,7 +379,10 @@ func (s *service) serve(ctx context.Context) {
serveError := make(chan error, 1)
go func() {
serveError <- srv.Serve(listener)
select {
case serveError <- srv.Serve(listener):
case <-ctx.Done():
}
}()
// Wait for stop, restart or error signals