make tests race-free
This commit is contained in:
@@ -29,11 +29,11 @@ func TestTraceLog(t *testing.T) {
|
|||||||
|
|
||||||
func TestTraceError(t *testing.T) {
|
func TestTraceError(t *testing.T) {
|
||||||
var buf mockWriter
|
var buf mockWriter
|
||||||
|
atomic.StoreUint32(&initialized, 1)
|
||||||
|
errorLog = newLogWriter(log.New(&buf, "", flags))
|
||||||
ctx := context.WithValue(context.Background(), tracespec.TracingKey, mock)
|
ctx := context.WithValue(context.Background(), tracespec.TracingKey, mock)
|
||||||
l := WithContext(ctx).(*traceLogger)
|
l := WithContext(ctx).(*traceLogger)
|
||||||
SetLevel(InfoLevel)
|
SetLevel(InfoLevel)
|
||||||
atomic.StoreUint32(&initialized, 1)
|
|
||||||
errorLog = newLogWriter(log.New(&buf, "", flags))
|
|
||||||
l.WithDuration(time.Second).Error(testlog)
|
l.WithDuration(time.Second).Error(testlog)
|
||||||
assert.True(t, strings.Contains(buf.String(), mockTraceId))
|
assert.True(t, strings.Contains(buf.String(), mockTraceId))
|
||||||
assert.True(t, strings.Contains(buf.String(), mockSpanId))
|
assert.True(t, strings.Contains(buf.String(), mockSpanId))
|
||||||
@@ -45,11 +45,11 @@ func TestTraceError(t *testing.T) {
|
|||||||
|
|
||||||
func TestTraceInfo(t *testing.T) {
|
func TestTraceInfo(t *testing.T) {
|
||||||
var buf mockWriter
|
var buf mockWriter
|
||||||
|
atomic.StoreUint32(&initialized, 1)
|
||||||
|
infoLog = newLogWriter(log.New(&buf, "", flags))
|
||||||
ctx := context.WithValue(context.Background(), tracespec.TracingKey, mock)
|
ctx := context.WithValue(context.Background(), tracespec.TracingKey, mock)
|
||||||
l := WithContext(ctx).(*traceLogger)
|
l := WithContext(ctx).(*traceLogger)
|
||||||
SetLevel(InfoLevel)
|
SetLevel(InfoLevel)
|
||||||
atomic.StoreUint32(&initialized, 1)
|
|
||||||
infoLog = newLogWriter(log.New(&buf, "", flags))
|
|
||||||
l.WithDuration(time.Second).Info(testlog)
|
l.WithDuration(time.Second).Info(testlog)
|
||||||
assert.True(t, strings.Contains(buf.String(), mockTraceId))
|
assert.True(t, strings.Contains(buf.String(), mockTraceId))
|
||||||
assert.True(t, strings.Contains(buf.String(), mockSpanId))
|
assert.True(t, strings.Contains(buf.String(), mockSpanId))
|
||||||
@@ -61,11 +61,11 @@ func TestTraceInfo(t *testing.T) {
|
|||||||
|
|
||||||
func TestTraceSlow(t *testing.T) {
|
func TestTraceSlow(t *testing.T) {
|
||||||
var buf mockWriter
|
var buf mockWriter
|
||||||
|
atomic.StoreUint32(&initialized, 1)
|
||||||
|
slowLog = newLogWriter(log.New(&buf, "", flags))
|
||||||
ctx := context.WithValue(context.Background(), tracespec.TracingKey, mock)
|
ctx := context.WithValue(context.Background(), tracespec.TracingKey, mock)
|
||||||
l := WithContext(ctx).(*traceLogger)
|
l := WithContext(ctx).(*traceLogger)
|
||||||
SetLevel(InfoLevel)
|
SetLevel(InfoLevel)
|
||||||
atomic.StoreUint32(&initialized, 1)
|
|
||||||
slowLog = newLogWriter(log.New(&buf, "", flags))
|
|
||||||
l.WithDuration(time.Second).Slow(testlog)
|
l.WithDuration(time.Second).Slow(testlog)
|
||||||
assert.True(t, strings.Contains(buf.String(), mockTraceId))
|
assert.True(t, strings.Contains(buf.String(), mockTraceId))
|
||||||
assert.True(t, strings.Contains(buf.String(), mockSpanId))
|
assert.True(t, strings.Contains(buf.String(), mockSpanId))
|
||||||
@@ -77,10 +77,10 @@ func TestTraceSlow(t *testing.T) {
|
|||||||
|
|
||||||
func TestTraceWithoutContext(t *testing.T) {
|
func TestTraceWithoutContext(t *testing.T) {
|
||||||
var buf mockWriter
|
var buf mockWriter
|
||||||
l := WithContext(context.Background()).(*traceLogger)
|
|
||||||
SetLevel(InfoLevel)
|
|
||||||
atomic.StoreUint32(&initialized, 1)
|
atomic.StoreUint32(&initialized, 1)
|
||||||
infoLog = newLogWriter(log.New(&buf, "", flags))
|
infoLog = newLogWriter(log.New(&buf, "", flags))
|
||||||
|
l := WithContext(context.Background()).(*traceLogger)
|
||||||
|
SetLevel(InfoLevel)
|
||||||
l.WithDuration(time.Second).Info(testlog)
|
l.WithDuration(time.Second).Info(testlog)
|
||||||
assert.False(t, strings.Contains(buf.String(), mockTraceId))
|
assert.False(t, strings.Contains(buf.String(), mockTraceId))
|
||||||
assert.False(t, strings.Contains(buf.String(), mockSpanId))
|
assert.False(t, strings.Contains(buf.String(), mockSpanId))
|
||||||
|
|||||||
Reference in New Issue
Block a user