From 5c7208677249a7f38fe9c063abfd676eff4f9bed Mon Sep 17 00:00:00 2001 From: anykno Date: Sun, 12 Jun 2022 22:13:52 +0800 Subject: [PATCH] fix: GossipState setKey did not save new value correctly --- cluster/gossip_state_management.go | 2 +- cluster/informer_test.go | 28 ++++++++++++++++++++++++---- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/cluster/gossip_state_management.go b/cluster/gossip_state_management.go index 6a95afe1b..1b7bbddb7 100644 --- a/cluster/gossip_state_management.go +++ b/cluster/gossip_state_management.go @@ -43,7 +43,7 @@ func setKey(state *GossipState, key string, value proto.Message, memberID string sequenceNo++ entry.SequenceNumber = sequenceNo - a, _ := anypb.New(entry.Value) + a, _ := anypb.New(value) entry.Value = a return sequenceNo diff --git a/cluster/informer_test.go b/cluster/informer_test.go index ff684b0c0..f80fc7a06 100644 --- a/cluster/informer_test.go +++ b/cluster/informer_test.go @@ -46,8 +46,11 @@ func TestInformer_GetState(t *testing.T) { t.Error("not ok") } - var s2 *MemberHeartbeat - _ = x.UnmarshalTo(s2) + var s2 MemberHeartbeat + err := x.UnmarshalTo(&s2) + if err != nil { + t.Error("unmarshal state error") + } } func TestInformer_ReceiveState(t *testing.T) { @@ -84,18 +87,35 @@ func TestInformer_ReceiveState(t *testing.T) { var ok bool - _, ok = m["member1"] + m1, ok := m["member1"] if !ok { t.Error("member1 is missing") } + var s1 MemberHeartbeat + + err := m1.UnmarshalTo(&s1) + + if err != nil { + t.Error("unmarshal member1 state error") + } + // ensure we see member2 after receiving state - _, ok = m["member2"] + m2, ok := m["member2"] if !ok { t.Error("member2 is missing") } + + var s2 MemberHeartbeat + + err = m2.UnmarshalTo(&s2) + + if err != nil { + t.Error("unmarshal member2 state error") + } + } func TestInformer_SendState(t *testing.T) {