From 0419ce65005190c25b5a86559919c2185e6b632f Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Mon, 5 Jun 2023 00:04:47 +0300 Subject: fix --- internal/quorum/quorum.go | 11 ++++++++--- internal/quorum/quorum_test.go | 2 ++ 2 files changed, 10 insertions(+), 3 deletions(-) (limited to 'internal/quorum') diff --git a/internal/quorum/quorum.go b/internal/quorum/quorum.go index 79fea11..44834f3 100644 --- a/internal/quorum/quorum.go +++ b/internal/quorum/quorum.go @@ -40,6 +40,7 @@ func (quo Quorum) Start(ctx context.Context) <-chan []string { select { case <-time.After(vote.Expiry): if liveNodes, changed := quo.liveNodes(); changed { + quo.score() liveNodesCh <- liveNodes } case vote := <-quo.voteCh: @@ -108,15 +109,19 @@ func (quo *Quorum) liveNodes() ([]string, bool) { } for _, x := range newLiveNodes { + var found bool for _, y := range quo.prevLiveNodes { if x == y { - continue + found = true + break } - return newLiveNodes, false + } + if !found { + return newLiveNodes, true } } - return newLiveNodes, true + return newLiveNodes, false } func (quo Quorum) deleteExpiredVotes() (liveNodes []string) { diff --git a/internal/quorum/quorum_test.go b/internal/quorum/quorum_test.go index e1463e2..e8c02a7 100644 --- a/internal/quorum/quorum_test.go +++ b/internal/quorum/quorum_test.go @@ -142,7 +142,9 @@ func TestLiveNodes(t *testing.T) { t.Errorf("Expected live node list to be changed: %v", liveNodes) } + t.Log(quo.prevLiveNodes) if liveNodes, changed := quo.liveNodes(); changed { + t.Log(quo.prevLiveNodes) t.Errorf("Expected live node list not to be changed: %v", liveNodes) } } -- cgit v1.2.3