mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
etcdserver: add a test to verify not to send duplicated append responses
This commit is contained in:
parent
577d7c0df2
commit
e8f46ce341
@ -227,3 +227,44 @@ func TestConfgChangeBlocksApply(t *testing.T) {
|
||||
t.Fatalf("unexpected blocking on execution")
|
||||
}
|
||||
}
|
||||
|
||||
func TestProcessDuplicatedAppRespMessage(t *testing.T) {
|
||||
n := newNopReadyNode()
|
||||
cl := membership.NewCluster(zap.NewExample(), "abc")
|
||||
|
||||
rs := raft.NewMemoryStorage()
|
||||
p := mockstorage.NewStorageRecorder("")
|
||||
tr, sendc := newSendMsgAppRespTransporter()
|
||||
r := newRaftNode(raftNodeConfig{
|
||||
lg: zap.NewExample(),
|
||||
isIDRemoved: func(id uint64) bool { return cl.IsIDRemoved(types.ID(id)) },
|
||||
Node: n,
|
||||
transport: tr,
|
||||
storage: p,
|
||||
raftStorage: rs,
|
||||
})
|
||||
|
||||
s := &EtcdServer{
|
||||
lgMu: new(sync.RWMutex),
|
||||
lg: zap.NewExample(),
|
||||
r: *r,
|
||||
cluster: cl,
|
||||
SyncTicker: &time.Ticker{},
|
||||
}
|
||||
|
||||
s.start()
|
||||
defer s.Stop()
|
||||
|
||||
lead := uint64(1)
|
||||
|
||||
n.readyc <- raft.Ready{Messages: []raftpb.Message{
|
||||
{Type: raftpb.MsgAppResp, From: 2, To: lead, Term: 1, Index: 1},
|
||||
{Type: raftpb.MsgAppResp, From: 2, To: lead, Term: 1, Index: 2},
|
||||
{Type: raftpb.MsgAppResp, From: 2, To: lead, Term: 1, Index: 3},
|
||||
}}
|
||||
|
||||
got, want := <-sendc, 1
|
||||
if got != want {
|
||||
t.Errorf("count = %d, want %d", got, want)
|
||||
}
|
||||
}
|
||||
|
@ -1768,3 +1768,24 @@ func (s *snapTransporter) SendSnapshot(m snap.Message) {
|
||||
m.CloseWithError(nil)
|
||||
s.snapDoneC <- m
|
||||
}
|
||||
|
||||
type sendMsgAppRespTransporter struct {
|
||||
nopTransporter
|
||||
sendC chan int
|
||||
}
|
||||
|
||||
func newSendMsgAppRespTransporter() (rafthttp.Transporter, <-chan int) {
|
||||
ch := make(chan int, 1)
|
||||
tr := &sendMsgAppRespTransporter{sendC: ch}
|
||||
return tr, ch
|
||||
}
|
||||
|
||||
func (s *sendMsgAppRespTransporter) Send(m []raftpb.Message) {
|
||||
var send int
|
||||
for _, msg := range m {
|
||||
if msg.To != 0 {
|
||||
send++
|
||||
}
|
||||
}
|
||||
s.sendC <- send
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user