Skip to content

Commit

Permalink
Fix Client process instrumentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
vmihailenco committed Dec 30, 2016
1 parent 57efac6 commit 9556378
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 40 deletions.
35 changes: 0 additions & 35 deletions example_instrumentation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ import (
"sync/atomic"
"time"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

redis "gopkg.in/redis.v5"
)

Expand Down Expand Up @@ -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))
})

})
})
12 changes: 7 additions & 5 deletions redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
15 changes: 15 additions & 0 deletions redis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 9556378

Please sign in to comment.