-
Notifications
You must be signed in to change notification settings - Fork 409
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. check max redirects 2. add monkey test 3. fix pinger buffer
- Loading branch information
Showing
23 changed files
with
665 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
# Overlord | ||
|
||
## Version 1.5.2 | ||
1. max redirects 5. | ||
|
||
## Version 1.5.1 | ||
1. reset sub message only in nedd. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package cluster | ||
|
||
import ( | ||
"math/rand" | ||
"reflect" | ||
"testing" | ||
|
||
"overlord/lib/bufio" | ||
"overlord/proto" | ||
"overlord/proto/redis" | ||
|
||
"github.com/bouk/monkey" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestNodeConnMaxRedirect(t *testing.T) { | ||
monkey.Patch(newNodeConn, func(_ *cluster, addr string) proto.NodeConn { | ||
return &nodeConn{ | ||
nc: &redis.NodeConn{}, | ||
} | ||
}) | ||
|
||
nnc := newNodeConn(nil, "") | ||
cnc := nnc.(*nodeConn) | ||
rnc := cnc.nc.(*redis.NodeConn) | ||
bw := &bufio.Writer{} | ||
|
||
msgs := proto.GetMsgs(1) | ||
msg := msgs[0] | ||
req := &redis.Request{} | ||
msg.WithRequest(req) | ||
resp := &redis.RESP{} | ||
|
||
// msg stub | ||
monkey.PatchInstanceMethod(reflect.TypeOf(msg), "Request", func(*proto.Message) proto.Request { | ||
return req | ||
}) | ||
// nc stub | ||
monkey.PatchInstanceMethod(reflect.TypeOf(rnc), "Read", func(_ *redis.NodeConn, _ *proto.Message) error { | ||
return nil | ||
}) | ||
monkey.PatchInstanceMethod(reflect.TypeOf(rnc), "Bw", func(_ *redis.NodeConn) *bufio.Writer { | ||
return bw | ||
}) | ||
monkey.PatchInstanceMethod(reflect.TypeOf(rnc), "Close", func(_ *redis.NodeConn) error { | ||
return nil | ||
}) | ||
// req stub | ||
monkey.PatchInstanceMethod(reflect.TypeOf(req), "IsSupport", func(_ *redis.Request) bool { | ||
return true | ||
}) | ||
monkey.PatchInstanceMethod(reflect.TypeOf(req), "IsCtl", func(_ *redis.Request) bool { | ||
return false | ||
}) | ||
monkey.PatchInstanceMethod(reflect.TypeOf(req), "Reply", func(_ *redis.Request) *redis.RESP { | ||
return resp | ||
}) | ||
monkey.PatchInstanceMethod(reflect.TypeOf(req), "RESP", func(_ *redis.Request) *redis.RESP { | ||
return resp | ||
}) | ||
// resp stub | ||
monkey.PatchInstanceMethod(reflect.TypeOf(resp), "Type", func(_ *redis.RESP) byte { | ||
return '-' | ||
}) | ||
monkey.PatchInstanceMethod(reflect.TypeOf(resp), "Data", func(_ *redis.RESP) []byte { | ||
var ( | ||
s = [][]byte{ | ||
[]byte("ASK 1 127.0.0.1:31234"), | ||
[]byte("MOVED 1 127.0.0.1:31234"), | ||
} | ||
) | ||
return s[rand.Intn(2)] | ||
}) | ||
monkey.PatchInstanceMethod(reflect.TypeOf(resp), "Encode", func(_ *redis.RESP, _ *bufio.Writer) error { | ||
return nil | ||
}) | ||
// bw stub | ||
monkey.PatchInstanceMethod(reflect.TypeOf(bw), "Write", func(_ *bufio.Writer, _ []byte) error { | ||
return nil | ||
}) | ||
monkey.PatchInstanceMethod(reflect.TypeOf(bw), "Flush", func(_ *bufio.Writer) error { | ||
return nil | ||
}) | ||
|
||
for i := 0; i < 10; i++ { | ||
err := nnc.Read(msg) | ||
assert.NoError(t, err) | ||
} | ||
|
||
monkey.UnpatchAll() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
package cluster | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
|
||
"overlord/lib/bufio" | ||
"overlord/proto" | ||
"overlord/proto/redis" | ||
|
||
"github.com/bouk/monkey" | ||
"github.com/pkg/errors" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestProxyConn(t *testing.T) { | ||
pc := &proxyConn{ | ||
c: &cluster{}, | ||
pc: &redis.ProxyConn{}, | ||
} | ||
pc.c.fakeNodesBytes = []byte("fake nodes bytes") | ||
pc.c.fakeSlotsBytes = []byte("fake slots bytes") | ||
bw := &bufio.Writer{} | ||
msgs := proto.GetMsgs(1) | ||
msg := msgs[0] | ||
req := &redis.Request{} | ||
msg.WithRequest(req) | ||
resp := &redis.RESP{} | ||
|
||
// pc stub | ||
monkey.PatchInstanceMethod(reflect.TypeOf(pc.pc), "Bw", func(_ *redis.ProxyConn) *bufio.Writer { | ||
return bw | ||
}) | ||
// msg stub | ||
monkey.PatchInstanceMethod(reflect.TypeOf(msg), "IsBatch", func(*proto.Message) bool { | ||
return false | ||
}) | ||
monkey.PatchInstanceMethod(reflect.TypeOf(msg), "Request", func(*proto.Message) proto.Request { | ||
return req | ||
}) | ||
// req stub | ||
monkey.PatchInstanceMethod(reflect.TypeOf(req), "IsSupport", func(_ *redis.Request) bool { | ||
return false | ||
}) | ||
monkey.PatchInstanceMethod(reflect.TypeOf(req), "IsCtl", func(_ *redis.Request) bool { | ||
return false | ||
}) | ||
monkey.PatchInstanceMethod(reflect.TypeOf(req), "RESP", func(_ *redis.Request) *redis.RESP { | ||
return resp | ||
}) | ||
// resp stub | ||
monkey.PatchInstanceMethod(reflect.TypeOf(resp), "Array", func(_ *redis.RESP) []*redis.RESP { | ||
return []*redis.RESP{resp, resp} | ||
}) | ||
|
||
// case cmdNodesBytes | ||
var count int | ||
monkey.PatchInstanceMethod(reflect.TypeOf(resp), "Data", func(_ *redis.RESP) []byte { | ||
if count == 0 { | ||
count++ | ||
return cmdClusterBytes | ||
} | ||
return cmdNodesBytes | ||
}) | ||
// bw stub | ||
monkey.PatchInstanceMethod(reflect.TypeOf(bw), "Write", func(_ *bufio.Writer, bs []byte) error { | ||
assert.Equal(t, pc.c.fakeNodesBytes, bs) | ||
return nil | ||
}) | ||
err := pc.Encode(msg) | ||
assert.NoError(t, err) | ||
|
||
// case cmdSlotsBytes | ||
count = 0 | ||
monkey.PatchInstanceMethod(reflect.TypeOf(resp), "Data", func(_ *redis.RESP) []byte { | ||
if count == 0 { | ||
count++ | ||
return cmdClusterBytes | ||
} | ||
return cmdSlotsBytes | ||
}) | ||
// bw stub | ||
monkey.PatchInstanceMethod(reflect.TypeOf(bw), "Write", func(_ *bufio.Writer, bs []byte) error { | ||
assert.Equal(t, pc.c.fakeSlotsBytes, bs) | ||
return nil | ||
}) | ||
err = pc.Encode(msg) | ||
assert.NoError(t, err) | ||
|
||
// case not support | ||
count = 0 | ||
monkey.PatchInstanceMethod(reflect.TypeOf(resp), "Data", func(_ *redis.RESP) []byte { | ||
if count == 0 { | ||
count++ | ||
return cmdClusterBytes | ||
} | ||
return []byte("") | ||
}) | ||
// bw stub | ||
monkey.PatchInstanceMethod(reflect.TypeOf(bw), "Write", func(_ *bufio.Writer, bs []byte) error { | ||
assert.Equal(t, notSupportBytes, bs) | ||
return nil | ||
}) | ||
err = pc.Encode(msg) | ||
assert.NoError(t, err) | ||
|
||
// resp stub | ||
monkey.PatchInstanceMethod(reflect.TypeOf(resp), "Data", func(_ *redis.RESP) []byte { | ||
return cmdClusterBytes | ||
}) | ||
monkey.PatchInstanceMethod(reflect.TypeOf(resp), "Array", func(_ *redis.RESP) []*redis.RESP { | ||
return []*redis.RESP{resp} | ||
}) | ||
err = pc.Encode(msg) | ||
assert.EqualError(t, errors.Cause(err), ErrInvalidArgument.Error()) | ||
} |
Oops, something went wrong.