Skip to content
This repository has been archived by the owner on Apr 18, 2024. It is now read-only.

Commit

Permalink
Expose pool info for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
willscott committed Aug 31, 2023
1 parent 5f2ab23 commit 9989d73
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions caboose.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions internal/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,9 @@ package state
type State struct {
ActiveNodes any
AllNodes any
PoolController
}

type PoolController interface {
DoRefresh()
}
8 changes: 4 additions & 4 deletions pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
})
Expand Down

0 comments on commit 9989d73

Please sign in to comment.