|
|
@ -2,6 +2,7 @@ package consul
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/hashicorp/consul/consul/structs"
|
|
|
|
"os"
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
"time"
|
|
|
@ -75,3 +76,42 @@ func TestClient_JoinLAN(t *testing.T) {
|
|
|
|
t.Fatalf("expected consul server")
|
|
|
|
t.Fatalf("expected consul server")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func TestClient_RPC(t *testing.T) {
|
|
|
|
|
|
|
|
dir1, s1 := testServer(t)
|
|
|
|
|
|
|
|
defer os.RemoveAll(dir1)
|
|
|
|
|
|
|
|
defer s1.Shutdown()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dir2, c1 := testClient(t)
|
|
|
|
|
|
|
|
defer os.RemoveAll(dir2)
|
|
|
|
|
|
|
|
defer c1.Shutdown()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Try an RPC
|
|
|
|
|
|
|
|
var out struct{}
|
|
|
|
|
|
|
|
if err := c1.RPC("Status.Ping", struct{}{}, &out); err != structs.ErrNoServers {
|
|
|
|
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Try to join
|
|
|
|
|
|
|
|
addr := fmt.Sprintf("127.0.0.1:%d",
|
|
|
|
|
|
|
|
s1.config.SerfLANConfig.MemberlistConfig.Port)
|
|
|
|
|
|
|
|
if err := c1.JoinLAN(addr); err != nil {
|
|
|
|
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Check the members
|
|
|
|
|
|
|
|
if len(s1.LANMembers()) != 2 {
|
|
|
|
|
|
|
|
t.Fatalf("bad len")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if len(c1.LANMembers()) != 2 {
|
|
|
|
|
|
|
|
t.Fatalf("bad len")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
time.Sleep(10 * time.Millisecond)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// RPC shoudl succeed
|
|
|
|
|
|
|
|
if err := c1.RPC("Status.Ping", struct{}{}, &out); err != nil {
|
|
|
|
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|