Fix Client process instrumentation.

This commit is contained in:
Vladimir Mihailenco 2016-12-30 12:58:04 +02:00
parent 57efac6c84
commit 9556378547
3 changed files with 22 additions and 40 deletions

View File

@ -5,9 +5,6 @@ import (
"sync/atomic" "sync/atomic"
"time" "time"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
redis "gopkg.in/redis.v5" 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))
})
})
})

View File

@ -293,12 +293,14 @@ type Client struct {
} }
func newClient(opt *Options, pool pool.Pooler) *Client { func newClient(opt *Options, pool pool.Pooler) *Client {
base := baseClient{opt: opt, connPool: pool} client := Client{
client := &Client{ baseClient: baseClient{
baseClient: base, opt: opt,
cmdable: cmdable{base.Process}, connPool: pool,
},
} }
return client client.cmdable.process = client.Process
return &client
} }
// NewClient returns a client to the Redis Server specified by Options. // NewClient returns a client to the Redis Server specified by Options.

View File

@ -199,6 +199,21 @@ var _ = Describe("Client", func() {
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
Expect(got).To(Equal(bigVal)) 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() { var _ = Describe("Client timeout", func() {