engine: GetSubsystemsStatus fix (#773)

* engine: GetSubsystemsStatus fix

* engine: force map literal to stop doubling up on keys, expanded test coverage

* engine: Deploy default for migration requirement.

* glorious: nits addr

* glorious: suggestion

* tests: fix
This commit is contained in:
Ryan O'Hara-Reid
2021-09-03 11:59:52 +10:00
committed by GitHub
parent a1a667bab9
commit a54c5107f4
12 changed files with 251 additions and 72 deletions

View File

@@ -1,6 +1,7 @@
package engine
import (
"errors"
"fmt"
"sync/atomic"
@@ -12,6 +13,8 @@ import (
// ConnectionManagerName is an exported subsystem name
const ConnectionManagerName = "internet_monitor"
var errConnectionCheckerIsNil = errors.New("connection checker is nil")
// connectionManager manages the connchecker
type connectionManager struct {
started int32
@@ -72,14 +75,17 @@ func (m *connectionManager) Start() error {
// Stop stops the connection manager
func (m *connectionManager) Stop() error {
if m == nil {
return fmt.Errorf("connection manager %w", ErrNilSubsystem)
return fmt.Errorf("connection manager: %w", ErrNilSubsystem)
}
if atomic.LoadInt32(&m.started) == 0 {
return fmt.Errorf("connection manager %w", ErrSubSystemNotStarted)
return fmt.Errorf("connection manager: %w", ErrSubSystemNotStarted)
}
defer func() {
atomic.CompareAndSwapInt32(&m.started, 1, 0)
}()
if m.conn == nil {
return fmt.Errorf("connection manager: %w", errConnectionCheckerIsNil)
}
log.Debugln(log.ConnectionMgr, "Connection manager shutting down...")
m.conn.Shutdown()
log.Debugln(log.ConnectionMgr, "Connection manager stopped.")