Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: use bytes.Equal instead #162

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/raft/file_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ func (f *FileSnapshotStore) Open(id string) (*SnapshotMeta, io.ReadCloser, error

// Verify the hash
computed := stateHash.Sum(nil)
if bytes.Compare(meta.CRC, computed) != 0 {
if !bytes.Equal(meta.CRC, computed) {
f.logger.Printf("[ERR] snapshot: CRC checksum failed (stored: %v computed: %v)",
meta.CRC, computed)
fh.Close()
Expand Down
4 changes: 2 additions & 2 deletions internal/raft/file_snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func TestFileSS_CreateSnapshot(t *testing.T) {
if latest.Term != 3 {
t.Fatalf("bad snapshot: %v", *latest)
}
if bytes.Compare(latest.Peers, peers) != 0 {
if !bytes.Equal(latest.Peers, peers) {
t.Fatalf("bad snapshot: %v", *latest)
}
if latest.Size != 13 {
Expand All @@ -156,7 +156,7 @@ func TestFileSS_CreateSnapshot(t *testing.T) {
}

// Ensure a match
if bytes.Compare(buf.Bytes(), []byte("first\nsecond\n")) != 0 {
if !bytes.Equal(buf.Bytes(), []byte("first\nsecond\n")) {
t.Fatalf("content mismatch")
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/raft/integ_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ CHECK:
}
for idx, log := range first.fsm.logs {
other := env.fsm.logs[idx]
if bytes.Compare(log, other) != 0 {
if !bytes.Equal(log, other) {
err = fmt.Errorf("log %d mismatch %v %v", idx, log, other)
goto ERR
}
Expand Down
2 changes: 1 addition & 1 deletion internal/raft/net_transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ func TestNetworkTransport_InstallSnapshot(t *testing.T) {
rpc.Reader.Read(buf)

// Compare
if bytes.Compare(buf, []byte("0123456789")) != 0 {
if !bytes.Equal(buf, []byte("0123456789")) {
t.Fatalf("bad buf %v", buf)
}

Expand Down
2 changes: 1 addition & 1 deletion internal/raft/raft.go
Original file line number Diff line number Diff line change
Expand Up @@ -1485,7 +1485,7 @@ func (r *Raft) requestVote(rpc RPC, req *RequestVoteRequest) {
// Check if we've voted in this election before
if lastVoteTerm == req.Term && lastVoteCandBytes != nil {
r.logger.Printf("[INFO] raft: Duplicate RequestVote for same term: %d", req.Term)
if bytes.Compare(lastVoteCandBytes, req.Candidate) == 0 {
if bytes.Equal(lastVoteCandBytes, req.Candidate) {
r.logger.Printf("[WARN] raft: Duplicate RequestVote from candidate: %s", req.Candidate)
resp.Granted = true
}
Expand Down
6 changes: 3 additions & 3 deletions internal/raft/raft_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ CHECK:
}

for idx := 0; idx < len(first.logs); idx++ {
if bytes.Compare(first.logs[idx], fsm.logs[idx]) != 0 {
if !bytes.Equal(first.logs[idx], fsm.logs[idx]) {
fsm.Unlock()
if time.Now().After(limit) {
c.FailNowf("[ERR] FSM log mismatch at index %d", idx)
Expand Down Expand Up @@ -775,10 +775,10 @@ func TestRaft_LeaderFail(t *testing.T) {
if len(fsm.logs) != 2 {
c.FailNowf("[ERR] did not apply both to FSM! %v", fsm.logs)
}
if bytes.Compare(fsm.logs[0], []byte("test")) != 0 {
if !bytes.Equal(fsm.logs[0], []byte("test")) {
c.FailNowf("[ERR] first entry should be 'test'")
}
if bytes.Compare(fsm.logs[1], []byte("apply")) != 0 {
if !bytes.Equal(fsm.logs[1], []byte("apply")) {
c.FailNowf("[ERR] second entry should be 'apply'")
}
fsm.Unlock()
Expand Down
2 changes: 1 addition & 1 deletion internal/raft/transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ func TestTransport_InstallSnapshot(t *testing.T) {
rpc.Reader.Read(buf)

// Compare
if bytes.Compare(buf, []byte("0123456789")) != 0 {
if !bytes.Equal(buf, []byte("0123456789")) {
t.Fatalf("bad buf %v", buf)
}

Expand Down