From 9989d730cb630da0f8c8acdd94c698ce3bd6134a Mon Sep 17 00:00:00 2001 From: Will Scott Date: Thu, 31 Aug 2023 14:39:16 +0200 Subject: [PATCH] Expose pool info for tests --- caboose.go | 1 + internal/state/state.go | 5 +++++ pool.go | 8 ++++---- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/caboose.go b/caboose.go index b78aa6c..e14fe94 100644 --- a/caboose.go +++ b/caboose.go @@ -164,6 +164,7 @@ func NewCaboose(config *Config) (*Caboose, error) { if c.config.Harness != nil { c.config.Harness.ActiveNodes = c.pool.ActiveNodes c.config.Harness.AllNodes = c.pool.AllNodes + c.config.Harness.PoolController = c.pool } // start the pool diff --git a/internal/state/state.go b/internal/state/state.go index 5881521..9c9e5f0 100644 --- a/internal/state/state.go +++ b/internal/state/state.go @@ -3,4 +3,9 @@ package state type State struct { ActiveNodes any AllNodes any + PoolController +} + +type PoolController interface { + DoRefresh() } diff --git a/pool.go b/pool.go index 18d40b8..f46f3c5 100644 --- a/pool.go +++ b/pool.go @@ -92,7 +92,7 @@ func (p *pool) Start() { go p.checkPool() } -func (p *pool) doRefresh() { +func (p *pool) DoRefresh() { newEP, err := p.loadPool() if err == nil { for _, n := range newEP { @@ -107,21 +107,21 @@ func (p *pool) doRefresh() { } } -// refreshPool is a background thread triggering `doRefresh` every `config.PoolRefresh` interval. +// refreshPool is a background thread triggering `DoRefresh` every `config.PoolRefresh` interval. func (p *pool) refreshPool() { t := time.NewTimer(0) started := sync.Once{} for { select { case <-t.C: - p.doRefresh() + p.DoRefresh() started.Do(func() { close(p.started) }) t.Reset(p.config.PoolRefresh) case <-p.refresh: - p.doRefresh() + p.DoRefresh() started.Do(func() { close(p.started) })