Skip to content

Commit

Permalink
fix: target manager is now properly checked for during shutdown
Browse files Browse the repository at this point in the history
Signed-off-by: Bruno Bressi <[email protected]>
  • Loading branch information
puffitos committed Jan 13, 2024
1 parent eb9016d commit 68d6c78
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 12 deletions.
4 changes: 2 additions & 2 deletions pkg/sparrow/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (s *Sparrow) Run(ctx context.Context) error {
s.cErr <- s.loader.Run(ctx)
}()
go func() {
if s.cfg.HasTargetManager() {
if s.tarMan != nil {
s.cErr <- s.tarMan.Reconcile(ctx)
}
}()
Expand Down Expand Up @@ -316,7 +316,7 @@ func (s *Sparrow) shutdown(ctx context.Context) {
s.shutOnce.Do(func() {
log.Info("Shutting down sparrow gracefully")
var errS error
if s.cfg.HasTargetManager() {
if s.tarMan != nil {
errS = s.tarMan.Shutdown(ctx)
}
errA := s.shutdownAPI(ctx)
Expand Down
11 changes: 1 addition & 10 deletions pkg/sparrow/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,20 +243,11 @@ func TestSparrow_Run_ContextCancel(t *testing.T) {
File: config.FileLoaderConfig{Path: "../config/testdata/config.yaml"},
Interval: time.Second * 1,
},
TargetManager: config.TargetManagerConfig{
CheckInterval: time.Second * 1,
RegistrationInterval: time.Second * 1,
UnhealthyThreshold: time.Second * 1,
Gitlab: config.GitlabTargetManagerConfig{
BaseURL: "https://gitlab.com",
Token: "my-cool-token",
ProjectID: 42,
},
},
}

// start sparrow
s := New(c)
s.tarMan = &gitlabmock.MockTargetManager{}
ctx, cancel := context.WithCancel(context.Background())
go func() {
err := s.Run(ctx)
Expand Down

0 comments on commit 68d6c78

Please sign in to comment.