Skip to content

Commit

Permalink
Merge pull request #14824 from fuweid/deflake-TestCompactHashCheckDet…
Browse files Browse the repository at this point in the history
…ectCorruption

tests/integration: deflake Corruption cases
  • Loading branch information
serathius authored Nov 22, 2022
2 parents 5a39c0f + 0b30e83 commit a87c993
Showing 1 changed file with 39 additions and 2 deletions.
41 changes: 39 additions & 2 deletions tests/integration/corrupt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,31 @@ func TestPeriodicCheckDetectsCorruption(t *testing.T) {
assert.NoError(t, err)
time.Sleep(50 * time.Millisecond)
leader := clus.WaitLeader(t)

// Get sorted member IDs
members, err := cc.MemberList(ctx)
assert.NoError(t, err, "error on member list %v")

// NOTE: If the corrupted member has been elected as leader, the
// alarm will show the smaller member.
var expectedID = uint64(clus.Members[0].ID())
if leader == 0 {
for _, m := range members.Members {
if m.Name != clus.Members[0].Name {
expectedID = m.ID
break
}
}

}

err = clus.Members[leader].Server.CorruptionChecker().PeriodicCheck()
assert.NoError(t, err, "error on periodic check")
time.Sleep(50 * time.Millisecond)

alarmResponse, err := cc.AlarmList(ctx)
assert.NoError(t, err, "error on alarm list")
assert.Equal(t, []*etcdserverpb.AlarmMember{{Alarm: etcdserverpb.AlarmType_CORRUPT, MemberID: uint64(clus.Members[0].ID())}}, alarmResponse.Alarms)
assert.Equal(t, []*etcdserverpb.AlarmMember{{Alarm: etcdserverpb.AlarmType_CORRUPT, MemberID: expectedID}}, alarmResponse.Alarms)
}

func TestCompactHashCheck(t *testing.T) {
Expand Down Expand Up @@ -166,9 +185,27 @@ func TestCompactHashCheckDetectCorruption(t *testing.T) {
assert.NoError(t, err)
time.Sleep(50 * time.Millisecond)
leader := clus.WaitLeader(t)

// Get sorted member IDs
members, err := cc.MemberList(ctx)
assert.NoError(t, err, "error on member list %v")

// NOTE: If the corrupted member has been elected as leader, the
// alarm will show the smaller member.
var expectedID = uint64(clus.Members[0].ID())
if leader == 0 {
for _, m := range members.Members {
if m.Name != clus.Members[0].Name {
expectedID = m.ID
break
}
}

}

clus.Members[leader].Server.CorruptionChecker().CompactHashCheck()
time.Sleep(50 * time.Millisecond)
alarmResponse, err := cc.AlarmList(ctx)
assert.NoError(t, err, "error on alarm list")
assert.Equal(t, []*etcdserverpb.AlarmMember{{Alarm: etcdserverpb.AlarmType_CORRUPT, MemberID: uint64(clus.Members[0].ID())}}, alarmResponse.Alarms)
assert.Equal(t, []*etcdserverpb.AlarmMember{{Alarm: etcdserverpb.AlarmType_CORRUPT, MemberID: expectedID}}, alarmResponse.Alarms)
}

0 comments on commit a87c993

Please sign in to comment.