Skip to content

Commit 165a860

Browse files
committed
Fix the data race in tests
1 parent 90bbf12 commit 165a860

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

file_logger_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package log
22

33
import (
4+
"sync"
45
"testing"
56
"time"
67

@@ -49,6 +50,8 @@ func TestFileLogger_WithAutoFlush(t *testing.T) {
4950
}
5051

5152
func TestFileLogger_WithAutoFlushWithCloseWhenWrite(t *testing.T) {
53+
var wg sync.WaitGroup
54+
wg.Add(1)
5255
wait := time.Second * 1
5356
autoFlushFileLogger, err := NewFileLoggerWithAutoFlush(level.DebugLevel, "./logs", "ns", true, wait)
5457
if err != nil {
@@ -57,9 +60,10 @@ func TestFileLogger_WithAutoFlushWithCloseWhenWrite(t *testing.T) {
5760
InitDefaultLogger(autoFlushFileLogger)
5861
go func() {
5962
Close()
63+
wg.Done()
6064
}()
6165
testLogs(t)
62-
<-time.After(wait + time.Second)
66+
wg.Wait()
6367
}
6468

6569
func TestFileLogger_WithAutoFlushWithFlushDelay(t *testing.T) {

0 commit comments

Comments
 (0)