Skip to content

Commit

Permalink
remove select for timer stop and fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
murali-reddy committed Oct 1, 2019
1 parent 1bb1ce4 commit 25e492a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
3 changes: 3 additions & 0 deletions gossip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"log"
"sync"
"testing"
"time"

"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -66,6 +67,8 @@ func sendPendingGossip(routers ...*Router) {
sentSomething = router.sendPendingGossip() || sentSomething
}
}
// add delay for periodic GC to get triggered after receiving topology gossip
time.Sleep(2 * time.Second)
}

func addTestGossipConnection(r1, r2 *Router) {
Expand Down
12 changes: 3 additions & 9 deletions peers.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,22 +350,16 @@ func (peers *Peers) forEach(fun func(*Peer)) {
}

func (peers *Peers) actorLoop() {
stop := func() {
if !peers.timer.Stop() {
select {
case <-peers.timer.C:
default:
}
}
}
for {
select {
case <-peers.timer.C:
peers.GarbageCollect()
// stop the timer so that next scheduled GarbageCollect() will be done
// only on receiving topology update
stop()
peers.timer.Stop()
peers.Lock()
peers.pendingGC = false
peers.Unlock()
}
}
}
Expand Down

0 comments on commit 25e492a

Please sign in to comment.