Skip to content

Commit

Permalink
e2e: fix TestWalletFormUnconfirmed
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisSchinnerl committed Mar 19, 2024
1 parent 91b482a commit 5cd4c1b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 30 deletions.
3 changes: 3 additions & 0 deletions autopilot/autopilot.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,9 @@ func (ap *Autopilot) Run() error {
return
}

// prune hosts that have been offline for too long
ap.s.PruneHosts(ap.shutdownCtx, autopilot.Config.Hosts)

// Log worker id chosen for this maintenance iteration.
workerID, err := w.ID(ap.shutdownCtx)
if err != nil {
Expand Down
40 changes: 14 additions & 26 deletions autopilot/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ type (
// a bit, we currently use inline interfaces to avoid having to update the
// scanner tests with every interface change
bus interface {
Autopilot(ctx context.Context, id string) (autopilot api.Autopilot, err error)
Hosts(ctx context.Context, opts api.GetHostsOptions) ([]hostdb.Host, error)
HostsForScanning(ctx context.Context, opts api.HostsForScanningOptions) ([]hostdb.HostAddress, error)
RemoveOfflineHosts(ctx context.Context, minRecentScanFailures uint64, maxDowntime time.Duration) (uint64, error)
Expand Down Expand Up @@ -199,44 +198,33 @@ func (s *scanner) tryPerformHostScan(ctx context.Context, w scanWorker, force bo
go func(st string) {
defer s.wg.Done()

var interrupted bool
for resp := range s.launchScanWorkers(ctx, w, s.launchHostScans()) {
if s.isInterrupted() || s.ap.isStopped() {
interrupted = true
break
}
if resp.err != nil && !strings.Contains(resp.err.Error(), "connection refused") {
s.logger.Error(resp.err)
}
}

// fetch the config right before removing offline hosts to get the most
// recent settings in case they were updated while scanning.
autopilot, err := s.bus.Autopilot(ctx, s.ap.id)
if err != nil {
s.logger.Errorf("tryPerformHostScan: failed to fetch autopilot config: %v", err)
return
}
hostCfg := autopilot.Config.Hosts
maxDowntime := time.Duration(hostCfg.MaxDowntimeHours) * time.Hour
minRecentScanFailures := hostCfg.MinRecentScanFailures

if !interrupted && maxDowntime > 0 {
s.logger.Debugf("removing hosts that have been offline for more than %v and have failed at least %d scans", maxDowntime, minRecentScanFailures)
removed, err := s.bus.RemoveOfflineHosts(ctx, minRecentScanFailures, maxDowntime)
if err != nil {
s.logger.Errorf("error occurred while removing offline hosts, err: %v", err)
} else if removed > 0 {
s.logger.Infof("removed %v offline hosts", removed)
}
}

s.mu.Lock()
s.scanning = false
s.logger.Debugf("%s finished after %v", st, time.Since(s.scanningLastStart))
s.mu.Unlock()
}(scanType)
return
}

func (s *scanner) PruneHosts(ctx context.Context, cfg api.HostsConfig) {
maxDowntime := time.Duration(cfg.MaxDowntimeHours) * time.Hour
minRecentScanFailures := cfg.MinRecentScanFailures
if maxDowntime > 0 {
s.logger.Debugf("removing hosts that have been offline for more than %v and have failed at least %d scans", maxDowntime, minRecentScanFailures)
removed, err := s.bus.RemoveOfflineHosts(ctx, minRecentScanFailures, maxDowntime)
if err != nil {
s.logger.Errorf("error occurred while removing offline hosts, err: %v", err)
} else if removed > 0 {
s.logger.Infof("removed %v offline hosts", removed)
}
}
}

func (s *scanner) tryUpdateTimeout() {
Expand Down
4 changes: 0 additions & 4 deletions autopilot/scanner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ type mockBus struct {
reqs []string
}

func (b *mockBus) Autopilot(ctx context.Context, id string) (autopilot api.Autopilot, err error) {
return api.Autopilot{}, nil
}

func (b *mockBus) Hosts(ctx context.Context, opts api.GetHostsOptions) ([]hostdb.Host, error) {
b.reqs = append(b.reqs, fmt.Sprintf("%d-%d", opts.Offset, opts.Offset+opts.Limit))

Expand Down

0 comments on commit 5cd4c1b

Please sign in to comment.