consul: test rpc errors returned from remote datacenters

This commit is contained in:
Ryan Uber 2014-09-30 14:19:25 -07:00
parent a1943afddc
commit cb795199d1
2 changed files with 29 additions and 1 deletions

View file

@ -325,6 +325,11 @@ func (s *Server) keyringRPC(
args *structs.KeyringRequest, args *structs.KeyringRequest,
replies *structs.KeyringResponses) error { replies *structs.KeyringResponses) error {
rlen := len(s.remoteConsuls) - 1
if rlen == 0 {
return nil
}
errorCh := make(chan error) errorCh := make(chan error)
respCh := make(chan *structs.KeyringResponses) respCh := make(chan *structs.KeyringResponses)
@ -335,7 +340,6 @@ func (s *Server) keyringRPC(
go s.forwardKeyringRPC(method, dc, args, errorCh, respCh) go s.forwardKeyringRPC(method, dc, args, errorCh, respCh)
} }
rlen := len(s.remoteConsuls) - 1
done := 0 done := 0
for { for {
select { select {

View file

@ -1,6 +1,8 @@
package consul package consul
import ( import (
"fmt"
"os"
"testing" "testing"
) )
@ -19,3 +21,25 @@ func TestUserEventNames(t *testing.T) {
t.Fatalf("bad: %v", raw) t.Fatalf("bad: %v", raw)
} }
} }
func TestKeyringRPCError(t *testing.T) {
dir1, s1 := testServerDC(t, "dc1")
defer os.RemoveAll(dir1)
defer s1.Shutdown()
dir2, s2 := testServerDC(t, "dc2")
defer os.RemoveAll(dir2)
defer s2.Shutdown()
// Try to join
addr := fmt.Sprintf("127.0.0.1:%d",
s1.config.SerfWANConfig.MemberlistConfig.BindPort)
if _, err := s2.JoinWAN([]string{addr}); err != nil {
t.Fatalf("err: %v", err)
}
// RPC error from remote datacenter is returned
if err := s1.keyringRPC("Bad.Method", nil, nil); err == nil {
t.Fatalf("bad")
}
}