From 9556378547ca70fd22bb7236b05483d368c47c89 Mon Sep 17 00:00:00 2001 From: Vladimir Mihailenco Date: Fri, 30 Dec 2016 12:58:04 +0200 Subject: [PATCH] Fix Client process instrumentation. --- example_instrumentation_test.go | 35 --------------------------------- redis.go | 12 ++++++----- redis_test.go | 15 ++++++++++++++ 3 files changed, 22 insertions(+), 40 deletions(-) diff --git a/example_instrumentation_test.go b/example_instrumentation_test.go index a627586b..009138eb 100644 --- a/example_instrumentation_test.go +++ b/example_instrumentation_test.go @@ -5,9 +5,6 @@ import ( "sync/atomic" "time" - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" - redis "gopkg.in/redis.v5" ) @@ -60,35 +57,3 @@ func wrapRedisProcess(client *redis.Client) { } }) } - -var _ = Describe("Instrumentation", func() { - var client *redis.Client - - BeforeEach(func() { - client = redis.NewClient(redisOptions()) - Expect(client.FlushDb().Err()).NotTo(HaveOccurred()) - }) - - AfterEach(func() { - Expect(client.Close()).NotTo(HaveOccurred()) - }) - - Describe("WrapProcess", func() { - - It("should call for client", func() { - wrapperFnCalled := false - - client.WrapProcess(func(oldProcess func(redis.Cmder) error) func(redis.Cmder) error { - return func(cmd redis.Cmder) error { - wrapperFnCalled = true - return oldProcess(cmd) - } - }) - - client.Ping() - - Expect(wrapperFnCalled).To(Equal(true)) - }) - - }) -}) diff --git a/redis.go b/redis.go index 3e9ee07e..894294d8 100644 --- a/redis.go +++ b/redis.go @@ -293,12 +293,14 @@ type Client struct { } func newClient(opt *Options, pool pool.Pooler) *Client { - base := baseClient{opt: opt, connPool: pool} - client := &Client{ - baseClient: base, - cmdable: cmdable{base.Process}, + client := Client{ + baseClient: baseClient{ + opt: opt, + connPool: pool, + }, } - return client + client.cmdable.process = client.Process + return &client } // NewClient returns a client to the Redis Server specified by Options. diff --git a/redis_test.go b/redis_test.go index e15c8719..69c68df7 100644 --- a/redis_test.go +++ b/redis_test.go @@ -199,6 +199,21 @@ var _ = Describe("Client", func() { Expect(err).NotTo(HaveOccurred()) Expect(got).To(Equal(bigVal)) }) + + It("should call WrapProcess", func() { + var wrapperFnCalled bool + + client.WrapProcess(func(oldProcess func(redis.Cmder) error) func(redis.Cmder) error { + return func(cmd redis.Cmder) error { + wrapperFnCalled = true + return oldProcess(cmd) + } + }) + + Expect(client.Ping().Err()).NotTo(HaveOccurred()) + + Expect(wrapperFnCalled).To(BeTrue()) + }) }) var _ = Describe("Client timeout", func() {