redis/request_test.go

65 lines
1.3 KiB
Go
Raw Normal View History

2012-07-27 15:43:30 +04:00
package redis_test
import (
2012-08-09 14:12:41 +04:00
"bufio"
2012-07-27 15:43:30 +04:00
. "launchpad.net/gocheck"
"github.com/vmihailenco/redis"
)
//------------------------------------------------------------------------------
2012-08-09 14:12:41 +04:00
type LineReader struct {
line []byte
}
func NewLineReader(line []byte) *LineReader {
return &LineReader{line: line}
}
func (r *LineReader) Read(buf []byte) (int, error) {
return copy(buf, r.line), nil
}
//------------------------------------------------------------------------------
2012-07-27 15:43:30 +04:00
type RequestTest struct{}
var _ = Suite(&RequestTest{})
//------------------------------------------------------------------------------
func (t *RequestTest) SetUpTest(c *C) {}
func (t *RequestTest) TearDownTest(c *C) {}
//------------------------------------------------------------------------------
func (t *RequestTest) BenchmarkStatusReq(c *C) {
c.StopTimer()
2012-08-09 14:12:41 +04:00
lineReader := NewLineReader([]byte("+OK\r\n"))
rd := bufio.NewReaderSize(lineReader, 1024)
2012-07-27 15:43:30 +04:00
req := redis.NewStatusReq()
for i := 0; i < 10; i++ {
vI, err := req.ParseReply(rd)
c.Check(err, IsNil)
c.Check(vI, Equals, "OK")
req.SetVal(vI)
2012-08-06 16:09:48 +04:00
c.Check(req.Err(), IsNil)
c.Check(req.Val(), Equals, "OK")
2012-07-27 15:43:30 +04:00
}
c.StartTimer()
for i := 0; i < c.N; i++ {
v, _ := req.ParseReply(rd)
req.SetVal(v)
2012-08-06 16:09:48 +04:00
req.Err()
req.Val()
2012-07-27 15:43:30 +04:00
}
}