*: clean up bool comparison

This commit is contained in:
Gyu-Ho Lee 2016-04-02 18:27:54 -07:00
parent b0cc0e443c
commit c09f23c46d
11 changed files with 39 additions and 40 deletions

View File

@ -133,7 +133,7 @@ func (rc *raftNode) publishEntries(ents []raftpb.Entry) bool {
// openWAL returns a WAL ready for reading.
func (rc *raftNode) openWAL() *wal.WAL {
if wal.Exist(rc.waldir) == false {
if !wal.Exist(rc.waldir) {
if err := os.Mkdir(rc.waldir, 0750); err != nil {
log.Fatalf("raftexample: cannot create dir for wal (%v)", err)
}

View File

@ -36,7 +36,7 @@ func deleteRevKey(kv v3.KV, key string, rev int64) (bool, error) {
txnresp, err := kv.Txn(context.TODO()).If(cmp).Then(req).Commit()
if err != nil {
return false, err
} else if txnresp.Succeeded == false {
} else if !txnresp.Succeeded {
return false, nil
}
return true, nil

View File

@ -84,7 +84,7 @@ func putNewKV(kv v3.KV, key, val string, leaseID v3.LeaseID) (int64, error) {
if err != nil {
return 0, err
}
if txnresp.Succeeded == false {
if !txnresp.Succeeded {
return 0, ErrKeyExists
}
return txnresp.Header.Revision, nil
@ -132,7 +132,7 @@ func newSequentialKV(kv v3.KV, prefix, val string, leaseID v3.LeaseID) (*RemoteK
if err != nil {
return nil, err
}
if txnresp.Succeeded == false {
if !txnresp.Succeeded {
return newSequentialKV(kv, prefix, val, leaseID)
}
return &RemoteKV{kv, newKey, txnresp.Header.Revision, val}, nil

View File

@ -410,14 +410,14 @@ func TestSortableNodes(t *testing.T) {
for _, n := range sns.Nodes {
cis = append(cis, int(n.CreatedIndex))
}
if sort.IntsAreSorted(cis) != true {
if !sort.IntsAreSorted(cis) {
t.Errorf("isSorted = %v, want %v", sort.IntsAreSorted(cis), true)
}
cis = make([]int, 0)
for _, n := range ns {
cis = append(cis, int(n.CreatedIndex))
}
if sort.IntsAreSorted(cis) != true {
if !sort.IntsAreSorted(cis) {
t.Errorf("isSorted = %v, want %v", sort.IntsAreSorted(cis), true)
}
}

View File

@ -27,10 +27,12 @@ type Comparable interface {
Compare(c Comparable) int
}
type rbcolor bool
type rbcolor int
const black = true
const red = false
const (
black rbcolor = iota
red
)
// Interval implements a Comparable interval [begin, end)
// TODO: support different sorts of intervals: (a,b), [a,b], (a, b]

View File

@ -152,10 +152,7 @@ func (l *raftLog) nextEnts() (ents []pb.Entry) {
// is a fast check without heavy raftLog.slice() in raftLog.nextEnts().
func (l *raftLog) hasNextEnts() bool {
off := max(l.applied+1, l.firstIndex())
if l.committed+1 > off {
return true
}
return false
return l.committed+1 > off
}
func (l *raftLog) snapshot() (pb.Snapshot, error) {

View File

@ -243,7 +243,7 @@ func TestLogMaybeAppend(t *testing.T) {
func() {
defer func() {
if r := recover(); r != nil {
if tt.wpanic != true {
if !tt.wpanic {
t.Errorf("%d: panic = %v, want %v", i, true, tt.wpanic)
}
}
@ -455,7 +455,7 @@ func TestCommitTo(t *testing.T) {
func() {
defer func() {
if r := recover(); r != nil {
if tt.wpanic != true {
if !tt.wpanic {
t.Errorf("%d: panic = %v, want %v", i, true, tt.wpanic)
}
}
@ -548,7 +548,7 @@ func TestCompaction(t *testing.T) {
func() {
defer func() {
if r := recover(); r != nil {
if tt.wallow == true {
if tt.wallow {
t.Errorf("%d: allow = %v, want %v: %v", i, false, true, r)
}
}

View File

@ -88,7 +88,7 @@ func TestRejectStaleTermMessage(t *testing.T) {
r.Step(pb.Message{Type: pb.MsgApp, Term: r.Term - 1})
if called == true {
if called {
t.Errorf("stepFunc called = %v, want %v", called, false)
}
}
@ -169,7 +169,7 @@ func testNonleaderStartElection(t *testing.T, state StateType) {
if r.state != StateCandidate {
t.Errorf("state = %s, want %s", r.state, StateCandidate)
}
if r.votes[r.id] != true {
if !r.votes[r.id] {
t.Errorf("vote for self = false, want true")
}
msgs := r.readMessages()
@ -326,7 +326,7 @@ func testNonleaderElectionTimeoutRandomized(t *testing.T, state StateType) {
}
for d := et + 1; d < 2*et; d++ {
if timeouts[d] != true {
if !timeouts[d] {
t.Errorf("timeout in %d ticks should happen", d)
}
}

View File

@ -83,7 +83,7 @@ func TestSnapshotFailure(t *testing.T) {
if sm.prs[2].Next != 1 {
t.Fatalf("Next = %d, want 1", sm.prs[2].Next)
}
if sm.prs[2].Paused != true {
if !sm.prs[2].Paused {
t.Errorf("Paused = %v, want true", sm.prs[2].Paused)
}
}
@ -106,7 +106,7 @@ func TestSnapshotSucceed(t *testing.T) {
if sm.prs[2].Next != 12 {
t.Fatalf("Next = %d, want 12", sm.prs[2].Next)
}
if sm.prs[2].Paused != true {
if !sm.prs[2].Paused {
t.Errorf("Paused = %v, want true", sm.prs[2].Paused)
}
}

View File

@ -250,12 +250,12 @@ func TestProgressResume(t *testing.T) {
Paused: true,
}
p.maybeDecrTo(1, 1)
if p.Paused != false {
if p.Paused {
t.Errorf("paused= %v, want false", p.Paused)
}
p.Paused = true
p.maybeUpdate(2)
if p.Paused != false {
if p.Paused {
t.Errorf("paused= %v, want false", p.Paused)
}
}
@ -268,7 +268,7 @@ func TestProgressResumeByHeartbeat(t *testing.T) {
r.prs[2].Paused = true
r.Step(pb.Message{From: 1, To: 1, Type: pb.MsgBeat})
if r.prs[2].Paused != false {
if r.prs[2].Paused {
t.Errorf("paused = %v, want false", r.prs[2].Paused)
}
}
@ -792,7 +792,7 @@ func TestStepIgnoreOldTermMsg(t *testing.T) {
sm.step = fakeStep
sm.Term = 2
sm.Step(pb.Message{Type: pb.MsgApp, Term: sm.Term - 1})
if called == true {
if called {
t.Errorf("stepFunc called = %v , want %v", called, false)
}
}
@ -1092,7 +1092,7 @@ func TestStateTransition(t *testing.T) {
func() {
defer func() {
if r := recover(); r != nil {
if tt.wallow == true {
if tt.wallow {
t.Errorf("%d: allow = %v, want %v", i, false, true)
}
}
@ -1416,7 +1416,7 @@ func TestSendAppendForProgressProbe(t *testing.T) {
t.Errorf("index = %d, want %d", msg[0].Index, 0)
}
if r.prs[2].Paused != true {
if !r.prs[2].Paused {
t.Errorf("paused = %v, want true", r.prs[2].Paused)
}
for j := 0; j < 10; j++ {
@ -1686,7 +1686,7 @@ func TestStepConfig(t *testing.T) {
if g := r.raftLog.lastIndex(); g != index+1 {
t.Errorf("index = %d, want %d", g, index+1)
}
if r.pendingConf != true {
if !r.pendingConf {
t.Errorf("pendingConf = %v, want true", r.pendingConf)
}
}
@ -1759,7 +1759,7 @@ func TestAddNode(t *testing.T) {
r := newTestRaft(1, []uint64{1}, 10, 1, NewMemoryStorage())
r.pendingConf = true
r.addNode(2)
if r.pendingConf != false {
if r.pendingConf {
t.Errorf("pendingConf = %v, want false", r.pendingConf)
}
nodes := r.nodes()
@ -1775,7 +1775,7 @@ func TestRemoveNode(t *testing.T) {
r := newTestRaft(1, []uint64{1, 2}, 10, 1, NewMemoryStorage())
r.pendingConf = true
r.removeNode(2)
if r.pendingConf != false {
if r.pendingConf {
t.Errorf("pendingConf = %v, want false", r.pendingConf)
}
w := []uint64{1}

View File

@ -38,7 +38,7 @@ import (
func TestStreamWriterAttachOutgoingConn(t *testing.T) {
sw := startStreamWriter(types.ID(1), newPeerStatus(types.ID(1)), &stats.FollowerStats{}, &fakeRaft{})
// the expected initial state of streamWriter is not working
if _, ok := sw.writec(); ok != false {
if _, ok := sw.writec(); ok {
t.Errorf("initial working status = %v, want false", ok)
}
@ -54,28 +54,28 @@ func TestStreamWriterAttachOutgoingConn(t *testing.T) {
for j := 0; j < 3; j++ {
testutil.WaitSchedule()
// previous attached connection should be closed
if prevwfc != nil && prevwfc.Closed() != true {
if prevwfc != nil && !prevwfc.Closed() {
continue
}
// write chan is available
if _, ok := sw.writec(); ok != true {
if _, ok := sw.writec(); !ok {
continue
}
}
// previous attached connection should be closed
if prevwfc != nil && prevwfc.Closed() != true {
if prevwfc != nil && !prevwfc.Closed() {
t.Errorf("#%d: close of previous connection = %v, want true", i, prevwfc.Closed())
}
// write chan is available
if _, ok := sw.writec(); ok != true {
if _, ok := sw.writec(); !ok {
t.Errorf("#%d: working status = %v, want true", i, ok)
}
sw.msgc <- raftpb.Message{}
testutil.WaitSchedule()
// write chan is available
if _, ok := sw.writec(); ok != true {
if _, ok := sw.writec(); !ok {
t.Errorf("#%d: working status = %v, want true", i, ok)
}
if wfc.Written() == 0 {
@ -85,10 +85,10 @@ func TestStreamWriterAttachOutgoingConn(t *testing.T) {
sw.stop()
// write chan is unavailable since the writer is stopped.
if _, ok := sw.writec(); ok != false {
if _, ok := sw.writec(); ok {
t.Errorf("working status after stop = %v, want false", ok)
}
if wfc.Closed() != true {
if !wfc.Closed() {
t.Errorf("failed to close the underlying connection")
}
}
@ -104,10 +104,10 @@ func TestStreamWriterAttachBadOutgoingConn(t *testing.T) {
sw.msgc <- raftpb.Message{}
testutil.WaitSchedule()
// no longer working
if _, ok := sw.writec(); ok != false {
if _, ok := sw.writec(); ok {
t.Errorf("working = %v, want false", ok)
}
if wfc.Closed() != true {
if !wfc.Closed() {
t.Errorf("failed to close the underlying connection")
}
}