Skip to content

Commit

Permalink
fixup! discovery: Make tests race clean.
Browse files Browse the repository at this point in the history
  • Loading branch information
j0sh committed Mar 30, 2020
1 parent 18fbcae commit 1e3835b
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions discovery/wh_discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@ func NewWebhookPool(bcast common.Broadcaster, callback *url.URL) *webhookPool {
func (w *webhookPool) getURLs() ([]*url.URL, error) {
w.mu.RLock()
lastReq := w.lastRequest
pool := w.pool
w.mu.RUnlock()

// retrive addrs from cache if time since lastRequest is less than the refresh interval
if time.Since(lastReq) < whRefreshInterval {
return w.pool.GetURLs(), nil
return pool.GetURLs(), nil
}

// retrive addrs from webhook if time since lastRequest is more than the refresh interval
Expand All @@ -61,16 +62,17 @@ func (w *webhookPool) getURLs() ([]*url.URL, error) {
if hash == w.responseHash {
w.mu.Lock()
w.lastRequest = time.Now()
pool = w.pool // may have been reset since beginning
w.mu.Unlock()
return w.pool.GetURLs(), nil
return pool.GetURLs(), nil
}

addrs, err := deserializeWebhookJSON(body)
if err != nil {
return nil, err
}

pool := NewOrchestratorPool(w.bcast, addrs)
pool = NewOrchestratorPool(w.bcast, addrs)

w.mu.Lock()
w.responseHash = hash
Expand Down

0 comments on commit 1e3835b

Please sign in to comment.