|
|
@ -91,10 +91,10 @@ func TestHookProcessPipelineCase1(t *testing.T) {
|
|
|
|
log.SetOutput(&buf)
|
|
|
|
log.SetOutput(&buf)
|
|
|
|
defer log.SetOutput(writer)
|
|
|
|
defer log.SetOutput(writer)
|
|
|
|
|
|
|
|
|
|
|
|
ctx, err := durationHook.BeforeProcessPipeline(context.Background(), []red.Cmder{red.NewCmd(context.Background())})
|
|
|
|
ctx, err := durationHook.BeforeProcessPipeline(context.Background(), []red.Cmder{
|
|
|
|
if err != nil {
|
|
|
|
red.NewCmd(context.Background()),
|
|
|
|
t.Fatal(err)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, "redis", tracesdk.SpanFromContext(ctx).(interface{ Name() string }).Name())
|
|
|
|
assert.Equal(t, "redis", tracesdk.SpanFromContext(ctx).(interface{ Name() string }).Name())
|
|
|
|
|
|
|
|
|
|
|
|
assert.Nil(t, durationHook.AfterProcessPipeline(ctx, []red.Cmder{
|
|
|
|
assert.Nil(t, durationHook.AfterProcessPipeline(ctx, []red.Cmder{
|
|
|
@ -115,10 +115,10 @@ func TestHookProcessPipelineCase2(t *testing.T) {
|
|
|
|
w, restore := injectLog()
|
|
|
|
w, restore := injectLog()
|
|
|
|
defer restore()
|
|
|
|
defer restore()
|
|
|
|
|
|
|
|
|
|
|
|
ctx, err := durationHook.BeforeProcessPipeline(context.Background(), []red.Cmder{red.NewCmd(context.Background())})
|
|
|
|
ctx, err := durationHook.BeforeProcessPipeline(context.Background(), []red.Cmder{
|
|
|
|
if err != nil {
|
|
|
|
red.NewCmd(context.Background()),
|
|
|
|
t.Fatal(err)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, "redis", tracesdk.SpanFromContext(ctx).(interface{ Name() string }).Name())
|
|
|
|
assert.Equal(t, "redis", tracesdk.SpanFromContext(ctx).(interface{ Name() string }).Name())
|
|
|
|
|
|
|
|
|
|
|
|
time.Sleep(slowThreshold.Load() + time.Millisecond)
|
|
|
|
time.Sleep(slowThreshold.Load() + time.Millisecond)
|
|
|
@ -159,7 +159,9 @@ func TestHookProcessPipelineCase5(t *testing.T) {
|
|
|
|
defer log.SetOutput(writer)
|
|
|
|
defer log.SetOutput(writer)
|
|
|
|
|
|
|
|
|
|
|
|
ctx := context.WithValue(context.Background(), startTimeKey, "foo")
|
|
|
|
ctx := context.WithValue(context.Background(), startTimeKey, "foo")
|
|
|
|
assert.Nil(t, durationHook.AfterProcessPipeline(ctx, []red.Cmder{red.NewCmd(context.Background())}))
|
|
|
|
assert.Nil(t, durationHook.AfterProcessPipeline(ctx, []red.Cmder{
|
|
|
|
|
|
|
|
red.NewCmd(context.Background()),
|
|
|
|
|
|
|
|
}))
|
|
|
|
assert.True(t, buf.Len() == 0)
|
|
|
|
assert.True(t, buf.Len() == 0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -167,11 +169,16 @@ func TestLogDuration(t *testing.T) {
|
|
|
|
w, restore := injectLog()
|
|
|
|
w, restore := injectLog()
|
|
|
|
defer restore()
|
|
|
|
defer restore()
|
|
|
|
|
|
|
|
|
|
|
|
logDuration(context.Background(), []red.Cmder{red.NewCmd(context.Background(), "get", "foo")}, 1*time.Second)
|
|
|
|
logDuration(context.Background(), []red.Cmder{
|
|
|
|
|
|
|
|
red.NewCmd(context.Background(), "get", "foo"),
|
|
|
|
|
|
|
|
}, 1*time.Second)
|
|
|
|
assert.True(t, strings.Contains(w.String(), "get foo"))
|
|
|
|
assert.True(t, strings.Contains(w.String(), "get foo"))
|
|
|
|
|
|
|
|
|
|
|
|
logDuration(context.Background(), []red.Cmder{red.NewCmd(context.Background(), "get", "foo"), red.NewCmd(context.Background(), "set", "bar", 0)}, 1*time.Second)
|
|
|
|
logDuration(context.Background(), []red.Cmder{
|
|
|
|
assert.True(t, strings.Contains(w.String(), "get foo\\nset bar 0"))
|
|
|
|
red.NewCmd(context.Background(), "get", "foo"),
|
|
|
|
|
|
|
|
red.NewCmd(context.Background(), "set", "bar", 0),
|
|
|
|
|
|
|
|
}, 1*time.Second)
|
|
|
|
|
|
|
|
assert.True(t, strings.Contains(w.String(), `get foo\nset bar 0`))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func injectLog() (r *strings.Builder, restore func()) {
|
|
|
|
func injectLog() (r *strings.Builder, restore func()) {
|
|
|
|