From 3fcaf5ae0521e3cfb3c07fde1fdd9579eccacb38 Mon Sep 17 00:00:00 2001 From: Takuto Nagami Date: Thu, 8 Jan 2026 13:20:48 +0900 Subject: [PATCH 1/3] remove hardcoded debug flag and b.N rewrite Signed-off-by: Takuto Nagami --- rawnode_test.go | 16 ++++------------ util_test.go | 3 +++ 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/rawnode_test.go b/rawnode_test.go index 24b92a36f..22060ea2d 100644 --- a/rawnode_test.go +++ b/rawnode_test.go @@ -988,12 +988,9 @@ func BenchmarkRawNode(b *testing.B) { } func benchmarkRawNodeImpl(b *testing.B, peers ...uint64) { - - const debug = false - s := newTestMemoryStorage(withPeers(peers...)) cfg := newTestConfig(1, 10, 1, s) - if !debug { + if !*debug { cfg.Logger = discardLogger // avoid distorting benchmark output } rn, err := NewRawNode(cfg) @@ -1009,7 +1006,7 @@ func benchmarkRawNodeImpl(b *testing.B, peers ...uint64) { for rn.HasReady() { numReady++ rd := rn.Ready() - if debug { + if *debug { b.Log(DescribeReady(rd, nil)) } if n := len(rd.CommittedEntries); n > 0 { @@ -1019,7 +1016,7 @@ func benchmarkRawNodeImpl(b *testing.B, peers ...uint64) { for _, m := range rd.Messages { if m.GetType() == pb.MsgVote { resp := &pb.Message{To: m.From, From: m.To, Term: m.Term, Type: pb.MsgVoteResp.Enum()} - if debug { + if *debug { b.Log(DescribeMessage(resp, nil)) } rn.Step(resp) @@ -1030,7 +1027,7 @@ func benchmarkRawNodeImpl(b *testing.B, peers ...uint64) { idx = m.GetEntries()[n-1].GetIndex() } resp := &pb.Message{To: m.From, From: m.To, Type: pb.MsgAppResp.Enum(), Term: m.Term, Index: new(idx)} - if debug { + if *debug { b.Log(DescribeMessage(resp, nil)) } rn.Step(resp) @@ -1044,11 +1041,6 @@ func benchmarkRawNodeImpl(b *testing.B, peers ...uint64) { rn.Campaign() stabilize() - if debug { - // nolint:staticcheck - b.N = 1 - } - var applied uint64 for i := 0; i < b.N; i++ { if err := rn.Propose([]byte("foo")); err != nil { diff --git a/util_test.go b/util_test.go index ce0971e88..3db968c6c 100644 --- a/util_test.go +++ b/util_test.go @@ -15,6 +15,7 @@ package raft import ( + "flag" "fmt" "math" "strings" @@ -27,6 +28,8 @@ import ( pb "go.etcd.io/raft/v3/raftpb" ) +var debug = flag.Bool("debug", false, "Debug logging in benchmarks.") + var testFormatter EntryFormatter = func(data []byte) string { return strings.ToUpper(string(data)) } From 676d5411ddbbdb079c7d991928ffa370918f24ed Mon Sep 17 00:00:00 2001 From: Takuto Nagami Date: Mon, 22 Jun 2026 14:06:12 +0900 Subject: [PATCH 2/3] fix flag name Signed-off-by: Takuto Nagami --- util_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util_test.go b/util_test.go index 3db968c6c..7446b0c13 100644 --- a/util_test.go +++ b/util_test.go @@ -28,7 +28,7 @@ import ( pb "go.etcd.io/raft/v3/raftpb" ) -var debug = flag.Bool("debug", false, "Debug logging in benchmarks.") +var debug = flag.Bool("bench.debug", false, "Debug logging in benchmarks.") var testFormatter EntryFormatter = func(data []byte) string { return strings.ToUpper(string(data)) From dac86148718b37f87569c3517f1198a70527b97b Mon Sep 17 00:00:00 2001 From: Takuto Nagami Date: Wed, 24 Jun 2026 12:23:44 +0900 Subject: [PATCH 3/3] fix the variable name based on the flag name Signed-off-by: Takuto Nagami --- rawnode_test.go | 8 ++++---- util_test.go | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/rawnode_test.go b/rawnode_test.go index 22060ea2d..cd47bb22a 100644 --- a/rawnode_test.go +++ b/rawnode_test.go @@ -990,7 +990,7 @@ func BenchmarkRawNode(b *testing.B) { func benchmarkRawNodeImpl(b *testing.B, peers ...uint64) { s := newTestMemoryStorage(withPeers(peers...)) cfg := newTestConfig(1, 10, 1, s) - if !*debug { + if !*benchDebug { cfg.Logger = discardLogger // avoid distorting benchmark output } rn, err := NewRawNode(cfg) @@ -1006,7 +1006,7 @@ func benchmarkRawNodeImpl(b *testing.B, peers ...uint64) { for rn.HasReady() { numReady++ rd := rn.Ready() - if *debug { + if *benchDebug { b.Log(DescribeReady(rd, nil)) } if n := len(rd.CommittedEntries); n > 0 { @@ -1016,7 +1016,7 @@ func benchmarkRawNodeImpl(b *testing.B, peers ...uint64) { for _, m := range rd.Messages { if m.GetType() == pb.MsgVote { resp := &pb.Message{To: m.From, From: m.To, Term: m.Term, Type: pb.MsgVoteResp.Enum()} - if *debug { + if *benchDebug { b.Log(DescribeMessage(resp, nil)) } rn.Step(resp) @@ -1027,7 +1027,7 @@ func benchmarkRawNodeImpl(b *testing.B, peers ...uint64) { idx = m.GetEntries()[n-1].GetIndex() } resp := &pb.Message{To: m.From, From: m.To, Type: pb.MsgAppResp.Enum(), Term: m.Term, Index: new(idx)} - if *debug { + if *benchDebug { b.Log(DescribeMessage(resp, nil)) } rn.Step(resp) diff --git a/util_test.go b/util_test.go index 7446b0c13..878c079d0 100644 --- a/util_test.go +++ b/util_test.go @@ -28,7 +28,7 @@ import ( pb "go.etcd.io/raft/v3/raftpb" ) -var debug = flag.Bool("bench.debug", false, "Debug logging in benchmarks.") +var benchDebug = flag.Bool("bench.debug", false, "Debug logging in benchmarks.") var testFormatter EntryFormatter = func(data []byte) string { return strings.ToUpper(string(data))