Skip to content

Commit

Permalink
Reduce time between polling. Fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
gammazero committed Jan 20, 2024
1 parent d6513f0 commit 9ed9a21
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"PublishExcept": null
},
"PollInterval": "6h0m0s",
"PollRetryAfter": "2h0m0s",
"PollRetryAfter": "10m0s",
"PollStopAfter": "168h0m0s",
"PollOverrides": null,
"UseAssigner": false
Expand Down
10 changes: 6 additions & 4 deletions internal/registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -1311,17 +1311,19 @@ func (r *Registry) pollProviders(normalPoll polling, pollOverrides map[peer.ID]p
return
}

// Sort from least to most recent.
// Sort from least to most recently polled.
sort.Slice(needPoll, func(i, j int) bool {
return needPoll[i].lastPoll < needPoll[j].lastPoll
})

// Do not poll more than the max, if it is set to non-zero. This selects
// the n least recently used.
// Do not poll more than the max when set to non-zero.
if maxPoll != 0 && len(needPoll) > maxPoll {
needPoll = needPoll[:maxPoll]
}
// Record last poll sequence for infos getting polled

// Record last poll sequence for infos getting polled. This avoids polling
// the same providers during each poll period, if there are others that
// should be polled.
r.provMutex.Lock()
for _, info := range needPoll {
info.lastPoll = pollSeq
Expand Down
6 changes: 3 additions & 3 deletions internal/registry/registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,16 +417,16 @@ func TestPollProvider(t *testing.T) {
// Check that registry is not blocked by unread auto-sync channel.
poll.retryAfter = 0
poll.deactivateAfter = 0
r.pollProviders(poll, nil, 2)
r.pollProviders(poll, nil, 3)
done := make(chan struct{})
go func() {
r.pollProviders(poll, nil, 2)
r.pollProviders(poll, nil, 3)
_, ok := r.ProviderInfo(peerID)
require.True(t, ok)
close(done)
}()

timeout.Reset(time.Second)
timeout.Reset(2 * time.Second)
select {
case <-done:
case <-timeout.C:
Expand Down

0 comments on commit 9ed9a21

Please sign in to comment.