From c6f75532fa728291355576aecfe29c0b92f7d9ad Mon Sep 17 00:00:00 2001 From: Qiu shao Date: Sun, 30 Nov 2025 21:44:53 +0800 Subject: [PATCH] Fix/logx test log mismatchtime schedule num (#5305) Co-authored-by: qiuwenhao --- core/fx/stream_test.go | 5 ++--- core/mr/mapreduce_test.go | 5 ----- core/threading/routinegroup_test.go | 6 ++---- core/threading/routines_test.go | 5 ++--- 4 files changed, 6 insertions(+), 15 deletions(-) diff --git a/core/fx/stream_test.go b/core/fx/stream_test.go index 4536f1afd..be3e155b0 100644 --- a/core/fx/stream_test.go +++ b/core/fx/stream_test.go @@ -1,8 +1,6 @@ package fx import ( - "io" - "log" "math/rand" "reflect" "runtime" @@ -13,6 +11,7 @@ import ( "time" "github.com/stretchr/testify/assert" + "github.com/zeromicro/go-zero/core/logx/logtest" "github.com/zeromicro/go-zero/core/stringx" "go.uber.org/goleak" ) @@ -238,7 +237,7 @@ func TestLast(t *testing.T) { func TestMap(t *testing.T) { runCheckedTest(t, func(t *testing.T) { - log.SetOutput(io.Discard) + logtest.Discard(t) tests := []struct { mapper MapFunc diff --git a/core/mr/mapreduce_test.go b/core/mr/mapreduce_test.go index fd0ac2b46..0fd5ad574 100644 --- a/core/mr/mapreduce_test.go +++ b/core/mr/mapreduce_test.go @@ -4,8 +4,6 @@ import ( "context" "errors" "fmt" - "io" - "log" "runtime" "sync/atomic" "testing" @@ -17,9 +15,6 @@ import ( var errDummy = errors.New("dummy") -func init() { - log.SetOutput(io.Discard) -} func TestFinish(t *testing.T) { defer goleak.VerifyNone(t) diff --git a/core/threading/routinegroup_test.go b/core/threading/routinegroup_test.go index 7f4dd086a..fce7ffff3 100644 --- a/core/threading/routinegroup_test.go +++ b/core/threading/routinegroup_test.go @@ -1,13 +1,12 @@ package threading import ( - "io" - "log" "sync" "sync/atomic" "testing" "github.com/stretchr/testify/assert" + "github.com/zeromicro/go-zero/core/logx/logtest" ) func TestRoutineGroupRun(t *testing.T) { @@ -25,8 +24,7 @@ func TestRoutineGroupRun(t *testing.T) { } func TestRoutingGroupRunSafe(t *testing.T) { - log.SetOutput(io.Discard) - + logtest.Discard(t) var count int32 group := NewRoutineGroup() var once sync.Once diff --git a/core/threading/routines_test.go b/core/threading/routines_test.go index 30a524eed..c23962c50 100644 --- a/core/threading/routines_test.go +++ b/core/threading/routines_test.go @@ -3,13 +3,12 @@ package threading import ( "bytes" "context" - "io" - "log" "testing" "github.com/stretchr/testify/assert" "github.com/zeromicro/go-zero/core/lang" "github.com/zeromicro/go-zero/core/logx" + "github.com/zeromicro/go-zero/core/logx/logtest" ) func TestRoutineId(t *testing.T) { @@ -17,7 +16,7 @@ func TestRoutineId(t *testing.T) { } func TestRunSafe(t *testing.T) { - log.SetOutput(io.Discard) + logtest.Discard(t) i := 0