소스 검색

fix data race in tests

kevin 4 년 전
부모
커밋
be39133dba
2개의 변경된 파일6개의 추가작업 그리고 1개의 파일을 삭제
  1. 5 0
      core/logx/tracelogger_test.go
  2. 1 1
      readme.md

+ 5 - 0
core/logx/tracelogger_test.go

@@ -4,6 +4,7 @@ import (
 	"context"
 	"log"
 	"strings"
+	"sync/atomic"
 	"testing"
 	"time"
 
@@ -31,6 +32,7 @@ func TestTraceError(t *testing.T) {
 	ctx := context.WithValue(context.Background(), tracespec.TracingKey, mock)
 	l := WithContext(ctx).(*traceLogger)
 	SetLevel(InfoLevel)
+	atomic.StoreUint32(&initialized, 1)
 	errorLog = newLogWriter(log.New(&buf, "", flags))
 	l.WithDuration(time.Second).Error(testlog)
 	assert.True(t, strings.Contains(buf.String(), mockTraceId))
@@ -46,6 +48,7 @@ func TestTraceInfo(t *testing.T) {
 	ctx := context.WithValue(context.Background(), tracespec.TracingKey, mock)
 	l := WithContext(ctx).(*traceLogger)
 	SetLevel(InfoLevel)
+	atomic.StoreUint32(&initialized, 1)
 	infoLog = newLogWriter(log.New(&buf, "", flags))
 	l.WithDuration(time.Second).Info(testlog)
 	assert.True(t, strings.Contains(buf.String(), mockTraceId))
@@ -61,6 +64,7 @@ func TestTraceSlow(t *testing.T) {
 	ctx := context.WithValue(context.Background(), tracespec.TracingKey, mock)
 	l := WithContext(ctx).(*traceLogger)
 	SetLevel(InfoLevel)
+	atomic.StoreUint32(&initialized, 1)
 	slowLog = newLogWriter(log.New(&buf, "", flags))
 	l.WithDuration(time.Second).Slow(testlog)
 	assert.True(t, strings.Contains(buf.String(), mockTraceId))
@@ -75,6 +79,7 @@ func TestTraceWithoutContext(t *testing.T) {
 	var buf mockWriter
 	l := WithContext(context.Background()).(*traceLogger)
 	SetLevel(InfoLevel)
+	atomic.StoreUint32(&initialized, 1)
 	infoLog = newLogWriter(log.New(&buf, "", flags))
 	l.WithDuration(time.Second).Info(testlog)
 	assert.False(t, strings.Contains(buf.String(), mockTraceId))

+ 1 - 1
readme.md

@@ -169,4 +169,4 @@ go get -u github.com/tal-tech/go-zero
 
 ## 9. 微信交流群
 
-<img src="doc/images/wechat.jpg" alt="wechat" width="300" />
+<img src="https://raw.githubusercontent.com/tal-tech/zero-doc/main/doc/images/wechat.jpg" alt="wechat" width="300" />