From edbc1d3b4aa430430dc3c4cab3f3c324dd7b4fd9 Mon Sep 17 00:00:00 2001 From: lsytj0413 <511121939@qq.com> Date: Fri, 10 Apr 2020 13:36:36 +0800 Subject: [PATCH] test(*): TestRollover failed randomly on Windows --- klog_test.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/klog_test.go b/klog_test.go index 404c058f..a298b739 100644 --- a/klog_test.go +++ b/klog_test.go @@ -28,6 +28,7 @@ import ( "runtime" "strconv" "strings" + "sync" "testing" "time" ) @@ -317,13 +318,16 @@ func TestVmoduleOff(t *testing.T) { func TestSetOutputDataRace(t *testing.T) { setFlags() defer logging.swap(logging.newBuffers()) + var wg sync.WaitGroup for i := 1; i <= 50; i++ { go func() { logging.flushDaemon() }() } for i := 1; i <= 50; i++ { + wg.Add(1) go func() { + defer wg.Done() SetOutput(ioutil.Discard) }() } @@ -333,7 +337,9 @@ func TestSetOutputDataRace(t *testing.T) { }() } for i := 1; i <= 50; i++ { + wg.Add(1) go func() { + defer wg.Done() SetOutputBySeverity("INFO", ioutil.Discard) }() } @@ -342,6 +348,7 @@ func TestSetOutputDataRace(t *testing.T) { logging.flushDaemon() }() } + wg.Wait() } // vGlobs are patterns that match/don't match this file at V=2.